Debugging Visual Studio 2010 Templates - visual-studio-2010

I'm using the visual studio POCO Template for the Entity Framework, so far it has worked great, but since my database/tables are not Upper Cammel Case, but UPPER case, every time that i need to regenerate the entities, i also need to (manually) change the entities on the edmx to be upper cammel case... which is really annoying
what i would like to do is to change the template to translate the Database tables and columns to upper cammel case E.G.
MY_TABLE_NAME => MyTableName
For that i need to understand how the template (tt file) works, and if possible debugg it to know where the change needs to be made.
Thanks!

Grab a T4 template editor from the visual studio gallery. Don't worry, they all suck in one way or another.
A T4 template is about as complex as an ASPX page without codebehind. Its pretty simple to edit them. As for debugging, I believe you have to spin up one instance of Visual Studio and debug it by attaching another instance. Its a bit of a daunting task for someone without a lot of experience.
Depending on yours, the best thing might be to create a simple console application that has a single method to adjust your table names, then copypaste (please don't downvote me!) that method body into your T4 template.

You can include in the T4's C# code a call to
System.Diagnostics.Debugger.Break();
then when executed will "hit" the breakpoint, and ask to attach the debugger, attach Visual Studio (the 2nd Visual Studio will be debugging the first Visual Studio).

Related

Stop Visual Studio from adding using statements

It appears that Visual Studio 2019 is adding using statements when I do not intend for it to. While I do really like the right-click Quick Action to add a missing using, I do not want it happening when I do not ask for it.
It's hard to track down when this happens as I'm often typing quickly and only later on do I notice the new using.

Roslyn Code refactoring VSIX project -- How to add more to the VSIX?

I've created a visual studio extension with some nice refactoring features via a Code Refactoring (CodeRefactoringProvider) roslyn project, but there isn't really anything to it in terms of adding tooltips or menu items or doing something on startup.
If I wanted to do something like add a settings menu or tell the user that they're on a trial version, how/when could I even do it? Even though I'm working in a vsix, events don't seem to be exposed anywhere.
Do CodeRefactoringProviders run in a bit of a sandbox? Because I like the way it consumes my class, shows the user a preview and it fits into the editor amazingly, but of course I'd like more control because after all, the root of what you create is a VSIX which can do almost anything in the visual studio environment.
I'm sure I could limit the # of refactorings and show a popup.. but I'm fairly certain people would send death threats.
You can add other elements in just the same way you would in any other vsix in a Roslyn vsix. There are various ways to do this, such as creating a Visual Studio Package, using an ITextViewCreationListener, etc.
One sample that I created showed how to integrate a Tools Options page with a Roslyn code issue at http://code.msdn.microsoft.com/windowsdesktop/Roslyn-Code-Issue-with-84d792dd.

Querying Language service in Visual Studio Editor Extension to get Assembly, class and method info

I want to write an Editor extension for Visual Studio 2010.
In my extension I want to get information about the Class, method which is at the current caret position.
For example, if I am in an Event Handler and I have some code that shows a MessageBox using MessageBox.show(…) and the caret is at .Show,
I want to query VS Services to get a response which tell me that I the caret is at Show method of MessageBox class which is in System.Windows.Froms.dll version 4.0.40319 etc.
Is it possible?
There is no way to do this with the current APIs in Visual Studio 2010. This is why we're building the Roslyn APIs so you could. When you install the CTP, we setup a Roslyn instance that replaces the standard language services with the Roslyn ones, and you can ask your question directly to it.
If you don't want to be dependent upon running in the Roslyn instance (which I assume is the case), then it gets a bit trickier. You can invoke the parsers to understand you're on a call named MessageBox.Show, but to get the semantics you'd have build up a Compilation making sure you get all the project references and source files right. That's a far trickier proposition, so depending on your scenario you might want to "cheat" as much as possible.
Disclosure: I'm on the Roslyn team.

Visual studio 2010: Can't show design view

I have an problem in Visual Studio 2010:
I created an custom user control, that show some data, then I tryed to add it on a page.
When I did this, this error showed up... when I run (start debugging) my application, everything works fine, the only thing that is not working is Visual Studio design view.
What should I do to solve this?
Your control is displaying data - if it tries to get that data from a remote database (for example) that's not available at design time then this could cause the problem.
You need to either modify your code to cope with the data source being missing (probably a good idea anyway) or wrap the code in a "is this design mode" check.

T4 Code Generation missing in Visual Studio 2008?

So I decided to roll up my sleeves and try out the T4 code generation built into VS2008.
I was going to work off of this article:
http://www.olegsych.com/2008/09/t4-tutorial-creatating-your-first-code-generator/
So, I get to this part: "Click Project->Add New Item in the main menu and select Code Generation->File template in the dialog." and discover that the Code Generation category is missing on my machine. (Tried in both a VB and C# project).
Is there perhaps a seperate download to get T4 on your machine?
Update #1
So, I downloaded the T4 Toolbox from CodePlex: http://t4toolbox.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27563
And things seem sorted out now. I was under the impression that the download was required for VS2005 but not for VS2008. Oh well, looks like its a fresh release anyways so is likely worthwhile to download.
Update #2
It now seems I don't have all the template types shown in the article. I only have File, Template, Generator, Unit Test
"Generator" is not listed in the article, and there are 3 in the article that I don't have. Strange....
Try just creating a text file and giving it a .tt extension. VS should recognize it right away. You may just be missing the template.
Do you happen to use Visual Basic? T4 Toolbox only provides 4 project item templates for VB - File, Template, Generator and Unit Test. The other templates you may have seen in the tutorial screenshots are implemented in C# and generate C# code. It seemed inappropriate to make them available in Visual Basic projects.

Resources