T4 Code Generation missing in Visual Studio 2008? - visual-studio

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.

Related

Why Snippet Manager doesn't works?

I really want to use this plugin. But once I do "Export as Snippet", I can't see a new tab where I can manage the snippet, set the Shourcut and such (as shown in the video). I only see this popup:
What is going on? Add new item?
I've updated to the last (update 3) version of Visual Studio 2015, and I've Snippet Designer 1.6.2.
UPDATE - WORKAROUND, AND POSSIBLE FUTURE FIX
I have tested Snippet Designer with Web Forms (Web Site Projects), and it does not work as described in the video, i.e. with the snippet file being automatically created.
However, it is possible to continue working with Snippet Designer, by selecting the Project Item named Code Snippet, as follows:
Create or open a Web Site project.
Select the text you wish to make a Snippet. Right click and select Export as Snippet.
In the New File Dialog window that opens, you need to locate the File Type Code Snippet. The easiest way in a long list of installed File Templates is to use the search feature, typing snippet.
Click Add. The file will be added to your project, and now Snippet Designer will activate, and function as normal.
NOTE: This is creating a default C# Code Snippet file, not the snippet file that is included within the Snippet Designer .vsix archive; it makes no difference as both files are empty, and Snippet Designer has its own code for building the contents of a snippet file according to the relevant XML schema, as specified by Microsoft.
A possible reason why Snippet Designer does not automatically create the snippet file itself, as it does with other projects, is that Web Site projects use a different approach to project metadata; for example, they do not have a .csproj file, which is typically used to list the files within a project.
It could also be that the code creating the snippet file asks Visual Studio, via Automation, to create a new instance of the snippet file Item Template; on a default Visual Studio 2015 installation, the listing of available Item Templates for a Web Site Project are located in:
C:\Program Files (x86)\Microsoft Visual Studio
14.0\Web\WebNewFileItems\NewFileItems.vsdir
Snippet Designer also includes a .vsdir file that has an entry for its own bundled snippet file, the source can be viewed here:
https://github.com/mmanela/SnippetDesigner/blob/master/src/SnippetDesigner/Templates/SnippetFile.vsdir
I would suggest the author of Snippet Designer investigate if the entry here is the source of the problem.
Microsoft provide documentation for the metadata contained in .vsdir files here: Template Directory Description (.Vsdir) Files
I do actually recommend a different product. My original answer continues below:
CURRENT SITUATION
As has been documented on the Snippet Designer GitHub Issue Tracker, there are issues with specific project types not being recognised, and therefore features not available.
The last commit to the Snippet Designer GitHub project was 1 year ago (November 2015); in view of the number of unresolved issues and lack of development, I would suggest a known working open source alternative.
WORKING ALTERNATIVE
Code Snippet Studio is another free, open source project for creating, editing and managing Snippets that fully supports Visual Studio 2015 (including Update 3), and which is actively developed and released:
Code Snippet Studio
Code Snippet Studio is an extension for Visual Studio 2015 that makes it easy to create, edit, package, and share IntelliSense code snippets for Visual Studio 2015 and Visual Studio Code. For C# and Visual Basic snippets, it also provides live Roslyn code analysis as you type to immediately detect code issues.
Note that multiple languages, including C#, VB, SQL, HTML, JavaScript are supported, among others. The image below shows VB editing.
Code Snippet Studio runs as either a Tool Window in Visual Studio 2015, or, as a standalone application (which personally I find ideal for working alongside Visual Studio Code on a laptop, or to make quick updates to my snippet packages).
Features include Roslyn based intellisense and analysis while editing snippets, specification of namespaces that need to be imported to support the Snippet, the ability to export to Visual Studio or Visual Studio Code, and optionally, create a VSIX file for installation on multiple machines.
FURTHER INFORMATION
For more information, the following links are useful:
Channel 9 - A Look Behind Code Snippet Studio (with Video)
GitHub Project
Getting started Guide
Channel9 - One code snippet at a time [and more] with the Code Snippet Studio
This is a known problem, see github issues 57, 70, 84, 109. I can only suggest that you persuade addon author to fix it, or fix it yourself :)

Visual Studio trying to step into BCL cs files

When I step through my application and get to a object like List... the debugger looks for a List.cs file somewhere on disk, can't find it and then asks me where it is with some pop up window inside VS. I feel like this was some setting I made in the properties and now I don't know how to turn it off. VS 2012
I just encountered a similar error in VS2013 - in my case it was looking for Stack.cs in the BCL code. The fix for me was to go into Options > Debugging > General and check the "Enable Just My Code" checkbox.
You might have "Enable .NET Framework source stepping" enabled (see http://msdn.microsoft.com/en-us/library/cc667410.aspx). So when you are at List... and trying to step into, it will actually try, but you don't have the sources for that. There is also a new experience for using the .NET framework reference source that was announced recently: http://blogs.msdn.com/b/dotnet/archive/2014/02/24/a-new-look-for-net-reference-source.aspx

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.

What T4 editing tools exist?

I don't use T4 templates often; usually when I do it is editing those of other projects (specifically SubSonic & T4MVC). The experience is always quite unpleasant (and this is certainly why I don't use them more often).
These are the tools I know of, and neither of them quite fit the bill.
Clarius Visual T4.
Does not support Visual Studio 2010. Their blog mentions work ongoing, but that was 2 months ago with no updates since. Their support forum is filled with spam and questions about when VS2010 will be supported.
Most of the projects I work on are in Visual Studio 2010, and the templates I deal with require themselves to be run in the Visual Studio host (as they access project information through VS's automation object model). This is why I am looking for a VS2010 compatible editor.
Tangible T4 Editor
The first time I attempted to use this, I thought Visual Studio 2010 had crashed. Turns out I didn't wait long enough (it took over 2 minutes for the editor window to appear). Call me picky, but this alone puts me off of this tool.
I have a modified T4MVC template that works. After I install Tangible's T4 editor, the template fails with several errors. If I then uninstall Tangible's T4 editor, the template works again. So it would seem something about the editor changes the behavior of T4 in Visual Studio. Perhaps obviously, that's entirely unacceptable.
Are there any other T4 editors I missed? Does anyone else use these tools, encounter these same issues, and successfully work with them?
I should also say, the most important feature for me is simply to distinguish between code that runs as part of the template and code/text that gets output. Everything else is gravy.
DevArt has released a T4 editor add on for Visual Studio. It is free and it works well. They do not appear to have a version for Visual Studio 2012 yet, however.
I have also come across a ReSharper plugin for editing T4 files, but I have not used it and cannot comment on how well it works (or does not).
Check out the T4 Toolbox.

No IntelliSense for C++/CLI in Visual Studio 2010?

I just moved from Visual Studio 2008 to Visual Studio 2010 (final) and noticed one major flaw:
When I try to use AutoComplete in a C++ source file for managed C++, a small note in the footer appears:
IntelliSense for C++/CLI is not available
Uh, has IntelliSense for C++/CLI been dropped from Visual Studio 2010? Is there any way to get this back? It is rather useful...
You are correct. Unfortunately it has been dropped. You can check this opened issue on Microsoft's Connect website.
I'll just quote them for the sake of the answer:
Unfortunately in this release we had to cut the intellisense support for C++/CLI due to time constraints. If you want to get some intellisense like quick info and memberlist on the native classes you can get it by choosing no /clr support in the project properties.
About getting back intellisense, your best chances for now are using third-party tools like VA Assist for example. I've tried it with Visual Studio 2008 and its IntelliSense is a whole lot better than the default one.
It is available again in Visual Studio 2012.
If you want to get IntelliSense back, install Visual Assist X from Whole Tomato Software. Here you can get a 30-days trial to check the intellisense.
According to the Visual C++ Team Blog, C++/CLI Intellisense will be in the next version of Visual Studio, but not in a service pack for VS2010. That blog post also gives some detail as to what went wrong and led to this sad state.
I don't know if you can use this settings but it work for me. I only check the Common Language RunTime Support for the cpp files that use it. I do not check it for the whole project and I've got intellisense for all the files that don't use the CLI.
Yes! you can enable the IntelliSence, but in a tricky way. Follow these instructions:
Go to your project properties. (Right click on your project name in
Project Explorer, and select Properties. or simply Alt + Enter)
From Configuration Properties, select General
In the right-hand section, find "Common Language Runtime Support"
and change it to "No Common Language Runtime Support".
Click the OK Button.
Now the IntelliSence is working. But a problem is an error when you compile your code! (The error is: error LNK1123: failure during conversion to COFF: file invalid or corrupt)
You can simply go back to Project Properties an change Common Language Runtime Support to "Common Language Runtime Support, Old Syntax (/clr:oldSyntax)".
Good luck.
This solution is only if you don't want Common Language Runtime
It worked for me in VS2010
Go to Project Propreties > Configuration Properties > General > Common Language Runtime Support and set it to No Common Language Runtime Support.
This will work fine just after hitting Apply button.
As mentioned you could install some paid software such as "Visual Assist X from Whole Tomato Software".
or
You could use open source tools that contain intellisense*, one such tool is Qt Creator 3.3.1 (opensource). You have two options, either setup your entire project with Qt to compile using VS2010 compiler, or use Qt to link to your source files and compile with VS2010. You write your code in Qt, save, flip windows to vs2010 and compile and debug.
When changes are saved in Qt, vs2010 will automatically reload the source file in the project and you can compile.

Resources