Visual Studio 2010 Make and Install Templates

2019-01-30 06:37发布

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?

7条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-30 06:53

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

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

查看更多
冷血范
3楼-- · 2019-01-30 06:55

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

查看更多
疯言疯语
4楼-- · 2019-01-30 07:00

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

查看更多
ら.Afraid
5楼-- · 2019-01-30 07:07

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楼-- · 2019-01-30 07:09

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>
查看更多
你好瞎i
7楼-- · 2019-01-30 07:13

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.

查看更多
登录 后发表回答