Visual Studio 2010 Make and Install Templates

2019-01-30 06:16发布

问题:

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?

回答1:

Here's the MSDN article for templates. Hopefully it is similar:

http://msdn.microsoft.com/en-us/library/6db0hwky.aspx



回答2:

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.



回答3:

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>


回答4:

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



回答5:

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.



回答6:

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



回答7:

You can download and install VS 2010 SDK (or VS 2010 SP1 SDK) which contains new project templates such as Item Template template and Project Template template (I don't know if there's version for earlier versions of VS and if these templates are only for C# or not).

Visual Studio 2010 SP1 SDK: http://www.microsoft.com/download/en/details.aspx?id=21835

Visual Studio 2010 SDK: http://www.microsoft.com/download/en/details.aspx?id=2680