creating custom templates in visual studio & resharper - visual-studio

I would like to create custom templates for c# files, unit test classes, .aspx.cs etc so that common items to all files are included once they are created eg file headers. I am working with visual studio 2010 and resharper 6. What is the easiest way to create these files and is it possible to be able to share them a team of developers easily? Appreciate any assistance or information as to how I might achieve this.

Visual Studio templates are simple enough to create - you can distribute them to your colleagues to setup in the same location on their computers (or even create an installer, if you want to makes things even easier).
See Creating Project and Item Templates and the Introduction to Visual Studio Templates on MSDN.
Contents of a Template
All project and item templates, whether installed together with Visual Studio or created by you, function by using the same principles and have similar contents. All templates contain the following items:
The files to be created when the template is used. This includes source code files, embedded resources, project files, and so on.
One .vstemplate file. This file contains the metadata that provides Visual Studio the information it needs to display the template in the New Project and Add New Item dialog boxes and create a project or item from the template. For more information about .vstemplate files, see Visual Studio Template Metadata Files.
When these files are compressed into a .zip file and put in the correct folder, Visual Studio automatically displays them in the My Templates section of the New Project and Add New Item dialog boxes. For more information about template folders, see How to: Locate and Organize Project and Item Templates.

You should open Templates Explorer from ReSharper | Templates Explorer. Then select the File Templates tab. There are default templates that comes with ReSharper. You can examine them and see how you can write your own. Here's the documentation and there's a question for useful examples.

Related

How to share an SSRS Report Template across TFS?

The standard method of implementing a Reporting Services report template is to create an .RDL (report file) and place it in the Visual Studio Report Project template folder at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\ProjectItems\ReportProject
Since this is a purely local approach, is there a way to implement a shared and source controlled template that can be used from the new item menu?
Our current solution for this issue is to store our templates in our report solution, and copy/paste them for new reports. Just wondering if there's a better alternative.
You need to create this as a .vsix extension and then share it. If you update the package and version all Visual Studio instanced that have it installed will prompt the user to update.
How to: https://blogs.msdn.microsoft.com/vsx/2014/06/10/creating-a-vsix-deployable-project-or-item-template-with-custom-wizard-support/
Although you can setup your own repo to load it from, It's much easyer to use http://marketplace.visualstudio.com for distribution.

Generated T4 Files Not Added to Project from Visual Studio Extension

I am trying to generate code scaffolding for an in-house API. I created a T4 template which includes several other templates for each code file to be generated. I then wrote a Visual Studio Extension (VSIX) with a WPF form to capture user input and initiate the transforming of the T4 template. I am doing all of this in Visual Studio Professional 2013.
This is what I followed to Invoke the Text Transformation in a VS Extension
https://msdn.microsoft.com/en-us/library/gg586947%28v=vs.120%29.aspx?f=255&MSPPError=-2147217396
When testing the templates locally using Run custom tool, everything works perfectly. However, when testing the VS extension in an Experimental Instance of Visual Studio, the problem I am having is that after the transformation has been invoked [calling ITextTemplating.ProcessTemplate], the generated files are not placed into my open project. I verified that they exist in their appropriate folders in File Explorer.
I have searched high & low and can't find anything that talks about this. Any ideas?
The custom tool is using the Visual Studio API (DTE object) to add the generated files to the projects. I built something very similar and that is what I had to do. This project is a bit old but it is a great starting point for seeing how this can be done.
Basically you need to get a reference to the folder you want to add the new item to and then call AddFromFile. Also don't forget to save the project after you add all the items.

How can i load a template I have created in Visual Studio?

After creating a solution for a project, I exported it as a template. Now after exporting it automatically adds the template to my IDE and creates a ZIP file with all the project files and a .vstemplate extension file.
Now i am on another computer with visual studio and i wish to load this template and save it in the IDE, but i cannot find this option anywhere. The temporary solution i have is to open an empty web application and copy all the contents of the ZIP file not including the .vstemplate file. So my question is how can i load this template into my IDE?
When opening the vstemplate file in Visual Studio all i get is a text editor and XML data.
I am using Visual studio 2013 with Update 4.
Once you've exported your template, copy the entire ZIP file that was created to the folder C:\Users\[User Name]\Documents\Visual Studio 2013\Templates\ProjectTemplates. (You might want to use one of the provided subdirectories to keep your template organized.)
Restart Visual Studio, and then use the search bar in the New Project dialog to help you find the project template you just added.
For the record, it looks like using templates changes with VS2017. Your project template provider will have to publish via a new build mechanic, and it'll be a bit different than just dumping a .zip into a user folder:
Using Project/Item Templates:
https://learn.microsoft.com/en-us/visualstudio/extensibility/upgrading-custom-project-and-item-templates-for-visual-studio-2017
Create Project/Item Template:
https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-custom-project-and-item-templates

Create visual studio solution template - multiple projects

I'm stuck on this tutorial for creating a multi-project visual studio template. I'm specifically stuck on this line:
Select the files and folders to include in your template, right-click the selection, click Send To, and then click Compressed (zipped) Folder. The files and folders are compressed into a .zip file.
I did the following steps:
Create 2 projects. (MyProj.Web and MyProj.Service)
Reference MyProj.Service in MyProj.Web.
Export both. They are now in a .zip file.
What do I do from here?
My intentions are: Make solution folders where some dlls will be (DI, unit testing frameworks, etc). Have these dlls referenced. Reference projects in other projects. Rename part of the projects. For eg. the ability to replace {MyProj}.Service with NewName.Service
The other parts includes making the .vstemplate xml file and placing the zip in the ProjectTemplates.
Per the article:
Put the .zip template file in the Visual Studio project template
directory. By default, this directory is \My Documents\Visual Studio
2010\Templates\ProjectTemplates\
The Visual Studio template will then be available from File > New Project. If making a template for a single item, place it in the \ItemTemplates folder instead to make it available from the Add New Item context menu in Solution Explorer.

Visual Studio 2008: How to install an item template

I have created an Item Template using the "Export Template" wizard. I opened up the XML file and made a couple of minor changes, then rezipped the package. Then I checked the item template into source control so that everyone on the team can access it if they want.
But for the life of me I can't get the template to show up under My Templates when I go to Add->New Item.
I have tried copying the zip file into every conceivable directory:
The template directories listed under Tools->Projects and Solutions->General
All the subfolders of these directories (i.e. /Visual C#/, /Visual Web Developer/ etc)
But nothing shows up. Has anyone else managed to distribute Item Templates to their team mates before?
In order to have a VS item template appear, you need to make sure that you run "devenv.exe /installvstemplates" after you have copied the .zip file containing your .vstemplate and template code file into the %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\<Project Type> folder.
I've found that it's useful to wrap the whole thing up into an MSI that discovers the VS9 path, copies the Item/Project template to the necessary folder, and calls a custom action that shells out to devenv.exe passing the "/installvstemplates" switch. That way your colleagues just need to install the package and they are up and running!
Hope this helps.
Here are the two articles I found online:
First the one on how to create an item template:
http://msdn.microsoft.com/en-us/library/ms247113(VS.80).aspx
Second is how to get VS to locate the item template.
http://msdn.microsoft.com/en-us/library/y3kkate1(VS.80).aspx
As far as I can see you have to place your custom templates in:
My Documents\Visual Studio 2005\Templates\ProjectTemplates\Language\
Adam Berent

Resources