如何在Visual Studio VS中定義多項目模板

來源:互聯網
上載者:User

標籤:

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>

如何在Visual Studio VS中定義多項目模板

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.