Visual Studio 2010 Make and Install Templates

92,626

Solution 1

In Visual Studio's path you will find the default templates, these are a set of zip files that get expanded into the template cach.

They are stored in

  • Item Templates - %VSInstallDir%\Common7\IDE\ItemTemplates\
  • Project Templates - %VSInstallDir%\Common7\IDE\ProjectTemplates\

Extracting the {{.zip}} in question and recompressing with the modified contents will update the template. You can also copy these files to one of the respective template folders in %USERPROFILE%\Documents\Visual Studio 2010.

For information on building templates have a look at Visual Studio Templates on MSDN.

You then need to tell VS to rebuild the cache.

  1. Open a visual studio command line shell
  2. Execute devenv /installvstemplates

You can also use the "Export Template..." wizard from the file menu, however the exported template loses original content such as if statements.

Solution 2

I ran into problems with this and multiple custom templates. Each template (e.g. vstemplate + cs file) should be in it's own zip file. If you put several into the same zip it won't pick up any of them.

I also found that if you put them in:

$My Documents$\Visual Studio 2010\Templates\ItemTemplates

then you wont need run the command (devenv /installvstemplates) mentioned by Brett. Presumably this is only when modifying the existing ones in the install folder.

Here's a sample that I use for knocking up NUnit tests:

Code file (with .cs/relevant extension):

using System;
using System.Collections.Generic;
using System.Linq;  
using System.Text;
using NUnit.Framework;

namespace $rootnamespace$
{
    [TestFixture, Category("issue")]
    public class $safeitemname$
    {
        [SetUp]
        public void Setup()
        {

        }

        [Test]
        public void Test()
        {

        }
    }
}

Template file (with .vstemplate extension):

<VSTemplate Version="3.0.0" Type="Item"
            xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" >
  <TemplateData>
    <DefaultName>ATest.cs</DefaultName>
    <Name>NUnit test</Name>
    <Description>
        with [TestFixture] attribute set on class and one empty method 
        called Test that has [Test] attribute
    </Description>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>10</SortOrder>
    <Icon>someIcon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs"
                 ReplaceParameters="true">TheCodeFile.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

Solution 3

I'd try http://msdn.microsoft.com/en-us/library/ms185291.aspx - it seems like a good starting point, at least.

Solution 4

I was missing SharePoint 2010 and MOSS 2007 templates in Visual Studio 2010 development tool after my SharePoint installation. I reinstalled VS and found they were available. It looks like during installation of SharePoint pre-requisites for some reason I missed those templates from getting installed.

Solution 5

You can get the complete example implemented here: Multi-Project Templates with Wizard: Visual Studio 2010 Sample

Share:
92,626
RCIX
Author by

RCIX

Lua is underrated!

Updated on November 27, 2020

Comments

  • RCIX
    RCIX over 3 years

    I am using F# and i found that the available templates were a bit to sparse for my liking, and i want to make more. How would i go about doing that? also, how would i install these templates after I've made them?