visual-studio Visual Studio 2010 制作和安装模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/984703/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio 2010 Make and Install Templates
提问by RCIX
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?
我正在使用 F#,我发现可用模板有点稀少,我喜欢,我想制作更多。我该怎么做呢?另外,在我制作这些模板后,我将如何安装它们?
采纳答案by jasonh
Here's the MSDN article for templates. Hopefully it is similar:
这是模板的 MSDN 文章。希望它是相似的:
回答by Brett Ryan
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.
在 Visual Studio 的路径中,您将找到默认模板,这些是一组 zip 文件,可扩展到模板缓存中。
They are stored in
它们存储在
- Item Templates - %VSInstallDir%\Common7\IDE\ItemTemplates\
- Project Templates - %VSInstallDir%\Common7\IDE\ProjectTemplates\
- 项目模板 - %VSInstallDir%\Common7\IDE\ItemTemplates\
- 项目模板 - %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.
提取有问题的 {{.zip}} 并使用修改后的内容重新压缩将更新模板。您还可以将这些文件复制到%USERPROFILE%\Documents\Visual Studio 2010.
For information on building templates have a look at Visual Studio Templateson MSDN.
有关构建模板的信息,请查看MSDN上的Visual Studio 模板。
You then need to tell VS to rebuild the cache.
然后您需要告诉 VS 重建缓存。
- Open a visual studio command line shell
- Execute devenv /installvstemplates
- 打开 Visual Studio 命令行外壳
- 执行 devenv /installvstemplates
You can also use the "Export Template..." wizard from the file menu, however the exported template loses original content such as ifstatements.
您也可以使用文件菜单中的“导出模板...”向导,但是导出的模板会丢失if语句等原始内容。
回答by JonnyRaa
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.
我遇到了这个和多个自定义模板的问题。每个模板(例如 vstemplate + cs 文件)都应该在它自己的 zip 文件中。如果你把几个放在同一个拉链里,它就不会拿起任何一个。
I also found that if you put them in:
我还发现,如果你把它们放进去:
$My Documents$\Visual Studio 2010\Templates\ItemTemplates
$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.
那么你就不需要运行 Brett 提到的命令 (devenv /installvstemplates)。大概只有在修改安装文件夹中的现有文件时才会这样做。
Here's a sample that I use for knocking up NUnit tests:
这是我用于启动 NUnit 测试的示例:
Code file (with .cs/relevant extension):
代码文件(带有 .cs/相关扩展名):
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 扩展名):
<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>
回答by idealsdotcodin
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.
安装 SharePoint 后,我在 Visual Studio 2010 开发工具中缺少 SharePoint 2010 和 MOSS 2007 模板。我重新安装了 VS,发现它们可用。看起来在安装 SharePoint 先决条件的过程中,由于某种原因我错过了安装这些模板。
回答by penguat
I'd try http://msdn.microsoft.com/en-us/library/ms185291.aspx- it seems like a good starting point, at least.
我会尝试http://msdn.microsoft.com/en-us/library/ms185291.aspx- 至少,这似乎是一个很好的起点。
回答by Ashraf Alam
You can get the complete example implemented here: Multi-Project Templates with Wizard: Visual Studio 2010 Sample
您可以在此处获得完整的示例:Multi-Project Templates with Wizard: Visual Studio 2010 Sample
回答by Marcin Robaszyński
You can download and install VS 2010 SDK (or VS 2010 SP1 SDK) which contains new project templates such as Item Templatetemplate and Project Templatetemplate (I don't know if there's version for earlier versions of VS and if these templates are only for C# or not).
您可以下载并安装VS 2010 SDK(或VS 2010 SP1 SDK),其中包含新的项目模板,例如项目模板模板和项目模板模板(我不知道是否有适用于早期版本的VS,这些模板是否仅用于C# 与否)。
Visual Studio 2010 SP1 SDK: http://www.microsoft.com/download/en/details.aspx?id=21835
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
Visual Studio 2010 SDK:http: //www.microsoft.com/download/en/details.aspx?id=2680

