如何在Visual Studio VS中定义多项目模板

https://msdn.microsoft.com/en-us/library/ms185308.aspx

Multi-project templates act as containers for two or more projects. When a project based on a multi-project template is created from the New Project dialog box, every project in the template is added to the solution.

A multi-project template must include the following items, compressed into a .zip file:

  • A root .vstemplate file for the entire multi-project template. This root .vstemplate file contains the metadata that the New Project dialog box displays, and specifies where to find the .vstemplate files for the projects in this template. This file must be located at the root of the .zip file.
  • One or more folders that contain the files that are required for a complete project template. This includes all code files for the project, and also a .vstemplate file for the project.

For example, a multi-project template .zip file that has two projects could have the following files and directories:

MultiProjectTemplate.vstemplate

\Project1\Project1.vstemplate

\Project1\Project1.vbproj

\Project1\Class.vb

\Project2\Project2.vstemplate

\Project2\Project2.vbproj

\Project2\Class.vb

The root .vstemplate file for a multi-project template differs from a single-project template in the following ways:

  • The Type attribute of the VSTemplate element contains the value ProjectGroup. For example:

    <VSTemplate Version="2.0.0" Type="ProjectGroup"
        xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    
  • The TemplateContent element contains a ProjectCollection element that has one or more ProjectTemplateLink elements that define the paths to the .vstemplate files of the included projects. For example:
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink>
                Project1\Project1.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink>
                Project2\Project2.vstemplate
            </ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
    

Multi-project templates also behave differently than normal templates. Multi-project templates have the following unique characteristics:

  • Individual projects in a multi-project template cannot be assigned names by the New Project dialog box. Instead, use the ProjectName attribute on the ProjectTemplateLink element to specify the name for each project. For more information, see the first example in the following section.
  • Multi-project templates can contain projects written in different languages, but the entire template itself can only be put in one category by using the ProjectType element.

To create a multi-project template

  1. Create the projects to include in the multi-project template.
  2. Create .vstemplate files for every project. For more information, see How to: Create Project Templates.
  3. Create a root .vstemplate file that to contain the metadata for the multi-project template. For more information, see the first example in the following section.
  4. 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.
  5. Put the .zip template file in the Visual Studio project template directory. By default, this directory is \My Documents\Visual Studio Version\Templates\ProjectTemplates\.

Example

This example shows a basic multi-project root .vstemplate file. In this example, the template contains two projects, My Windows Application and My Class Library. The ProjectName attribute on the ProjectTemplateLink element sets the name for Visual Studio to assign this project. If the ProjectName attribute does not exist, the name of the .vstemplate file is used as the project name.

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>Multi-Project Template Sample</Name>
        <Description>An example of a multi-project template</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>VisualBasic</ProjectType>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink ProjectName="My Windows Application">
                WindowsApp\MyTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="My Class Library">
                ClassLib\MyTemplate.vstemplate
            </ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>

Example

This example uses the SolutionFolder element to divide the projects into two groups, Math Classes and Graphics Classes. The template contains four projects, two of which are placed in each solution folder.

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>Multi-Project Template Sample</Name>
        <Description>An example of a multi-project template</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>VisualBasic</ProjectType>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <SolutionFolder Name="Math Classes">
                <ProjectTemplateLink ProjectName="MathClassLib1">
                    MathClassLib1\MyTemplate.vstemplate
                </ProjectTemplateLink>
                <ProjectTemplateLink ProjectName="MathClassLib2">
                    MathClassLib2\MyTemplate.vstemplate
                </ProjectTemplateLink>
            </SolutionFolder>
            <SolutionFolder Name="Graphics Classes">
                <ProjectTemplateLink ProjectName="GraphicsClassLib1">
                    GraphicsClassLib1\MyTemplate.vstemplate
                </ProjectTemplateLink>
                <ProjectTemplateLink ProjectName="GraphicsClassLib2">
                    GraphicsClassLib2\MyTemplate.vstemplate
                </ProjectTemplateLink>
            </SolutionFolder>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>

Multi-project templates act as containers for two or more projects. When a project based on a multi-project template is created from the New Project dialog box, every project in the template is added to the solution.

A multi-project template must include the following items, compressed into a .zip file:

  • A root .vstemplate file for the entire multi-project template. This root .vstemplate file contains the metadata that the New Project dialog box displays, and specifies where to find the .vstemplate files for the projects in this template. This file must be located at the root of the .zip file.
  • One or more folders that contain the files that are required for a complete project template. This includes all code files for the project, and also a .vstemplate file for the project.

For example, a multi-project template .zip file that has two projects could have the following files and directories:

MultiProjectTemplate.vstemplate

\Project1\Project1.vstemplate

\Project1\Project1.vbproj

\Project1\Class.vb

\Project2\Project2.vstemplate

\Project2\Project2.vbproj

\Project2\Class.vb

The root .vstemplate file for a multi-project template differs from a single-project template in the following ways:

  • The Type attribute of the VSTemplate element contains the value ProjectGroup. For example:

    <VSTemplate Version="2.0.0" Type="ProjectGroup"
        xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    
  • The TemplateContent element contains a ProjectCollection element that has one or more ProjectTemplateLink elements that define the paths to the .vstemplate files of the included projects. For example:
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink>
                Project1\Project1.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink>
                Project2\Project2.vstemplate
            </ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
    

Multi-project templates also behave differently than normal templates. Multi-project templates have the following unique characteristics:

  • Individual projects in a multi-project template cannot be assigned names by the New Project dialog box. Instead, use the ProjectName attribute on the ProjectTemplateLink element to specify the name for each project. For more information, see the first example in the following section.
  • Multi-project templates can contain projects written in different languages, but the entire template itself can only be put in one category by using the ProjectType element.

To create a multi-project template

  1. Create the projects to include in the multi-project template.
  2. Create .vstemplate files for every project. For more information, see How to: Create Project Templates.
  3. Create a root .vstemplate file that to contain the metadata for the multi-project template. For more information, see the first example in the following section.
  4. 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.
  5. Put the .zip template file in the Visual Studio project template directory. By default, this directory is \My Documents\Visual Studio Version\Templates\ProjectTemplates\.

Example

This example shows a basic multi-project root .vstemplate file. In this example, the template contains two projects, My Windows Application and My Class Library. The ProjectName attribute on the ProjectTemplateLink element sets the name for Visual Studio to assign this project. If the ProjectName attribute does not exist, the name of the .vstemplate file is used as the project name.

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>Multi-Project Template Sample</Name>
        <Description>An example of a multi-project template</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>VisualBasic</ProjectType>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink ProjectName="My Windows Application">
                WindowsApp\MyTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="My Class Library">
                ClassLib\MyTemplate.vstemplate
            </ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>

Example

This example uses the SolutionFolder element to divide the projects into two groups, Math Classes and Graphics Classes. The template contains four projects, two of which are placed in each solution folder.

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>Multi-Project Template Sample</Name>
        <Description>An example of a multi-project template</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>VisualBasic</ProjectType>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <SolutionFolder Name="Math Classes">
                <ProjectTemplateLink ProjectName="MathClassLib1">
                    MathClassLib1\MyTemplate.vstemplate
                </ProjectTemplateLink>
                <ProjectTemplateLink ProjectName="MathClassLib2">
                    MathClassLib2\MyTemplate.vstemplate
                </ProjectTemplateLink>
            </SolutionFolder>
            <SolutionFolder Name="Graphics Classes">
                <ProjectTemplateLink ProjectName="GraphicsClassLib1">
                    GraphicsClassLib1\MyTemplate.vstemplate
                </ProjectTemplateLink>
                <ProjectTemplateLink ProjectName="GraphicsClassLib2">
                    GraphicsClassLib2\MyTemplate.vstemplate
                </ProjectTemplateLink>
            </SolutionFolder>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>
时间: 2024-10-28 13:21:07

如何在Visual Studio VS中定义多项目模板的相关文章

如何在Visual Studio 2013中使用Ribbon For WPF

1.首先需要 下载Ribbon For WPF.目前最新的版本是Microsoft Ribbon for WPF October 2010. 下载 链接: https://www.microsoft.com/en-us/download/details.aspx?id=11877#filelist 下载 完成后安装. 2.打开Visual Studio 2013创建WPF应用程序.添加程序集引用 "C:\Program Files (x86)\Microsoft Ribbon for WPF\V

如何在Visual Studio 2017中使用C# 7+语法

前言 之前不知看过哪位前辈的博文有点印象C# 7控制台开始支持执行异步方法,然后闲来无事,搞着,搞着没搞出来,然后就写了这篇博文,不喜勿喷,或许对您有帮助. 在Visual Studio 2017配置支持C# 7+语法 心想都VS2017了肯定是支持C# 7+语法,然后接着将控制台程序修改为异步,然后告知于我不行,尼玛这不是扯淡了么,如下: public class Program { public static async Task Main(string[] args) { using (v

如何在Visual Studio 2013中连接中国版的Azure

http://diaosbook.com/Post/2014/8/23/connect-azure-cn-in-vs2013 VS2013的Server Explorer在第一次连接Azure的时候默认弹出的登录框只能登录国际版的Azure.但是国内很多屌丝没有国际版怎么办呢?其实国内世纪互联运营的windowsazure.cn也可以通过导入订阅的方式来连接. 1. 登录国内版Azure之后,访问这个地址,下载你的订阅文件:https://manage.windowsazure.cn/publi

如何在Visual Studio Code中调用浏览器运行HTML代码

微软刚发布的Visual Studio Code还不支持安装扩展,没有内置的HTML预览功能.如果想要编辑HTML之后直接运行,可以 ctrl+shift+p 搜索 Configure Task Runner. 回车之后打开 tasks.json,修改一下: {     "version": "0.1.0",     "command": "explorer",     "windows": {      

SharpDX初学者教程第1部分:在Visual Studio 2013中设置SharpDX项目

原文 http://www.johanfalk.eu/blog/sharpdx-tutorial-part-1-setting-up-a-sharpdx-project-in-visual-studio-2013 这是我使用SharpDX的第一个教程.SharpDX允许您使用DirectX和C#渲染图形.我最近开始使用SharpDX,但是与其他选项相比,没有太多的文档和教程,因此我将继续编写这些教程. 注意:对于那些熟悉SharpDX的人,您可能知道它存在一个工具包,可以快速设置入门,这使得Ga

ASP.NET 5系列教程 (五):在Visual Studio 2015中使用Grunt、Bower开发Web程序

基于Visual Studio 2015,你可以: 方便的管理前端包,如jQuery, Bootstrap, 或Angular. 自动运行任务,如LESS.JavaScript压缩.JSLint.JavaScript单元测试等. 方便的获得Web开发者生态圈的工具包. 为了实现这些场景,Visual Studio 2015已经内置了一些流行的第三方工具包: Bower:Web包管理器,Bower可以帮你安装前端包,包括JavaScript.CSS类库.对于服务器端包,请通过NuGet包管理. G

ASP.NET 5系列教程 (五):在Visual Studio 2015中使用Grunt、Bowe

基于Visual Studio 2015,你可以: 方便的管理前端包,如jQuery, Bootstrap, 或Angular. 自动运行任务,如LESS.JavaScript压缩.JSLint.JavaScript单元测试等. 方便的获得Web开发者生态圈的工具包. 为了实现这些场景,Visual Studio 2015已经内置了一些流行的第三方工具包: Bower:Web包管理器,Bower可以帮你安装前端包,包括JavaScript.CSS类库.对于服务器端包,请通过NuGet包管理. G

Visual Studio 2017中使用SourceLink调试ASP.NET Core源码

背景 当我们在学习ASP.NET Core或者调试ASP.NET Core程序的时候,有时候需要调试底层代码,但是当我们在Visual Studio中调试程序的时候,由于一些基础库或者第三方库缺少pdb文件,所以调试这些库的代码的时候,会出现断点不能进去的情况. 例如,在如下代码中,我们希望调试一下View()方法,看看其中的内部实现 但是当我们点击F11之后,程序会直接跳到下一步 Source Link SourceLink是一组用于描述可嵌入到符号.二进制文件和包中的源代码控制元数据的包和规

如何在Visual Studio中选择C++和C#的编译器版本

博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:如何在Visual Studio中选择C++和C#的编译器版本.