Visual Studio 範本中繼資料檔

每個範本都包含一個攜帶中繼資料的 .vstemplate 檔,它可為 Visual Studio 提供關於在 [新增專案] 和 [加入新項目] 對話方塊中顯示該範本以及從該範本建立專案或項目的必要資訊。

.vstemplate 檔的結構

專案範本的 .vstemplate 檔是由三個基礎項目組成:

  • VSTemplate:用以識別範本為專案或項目範本,並且提供範本的版本編號。

  • TemplateData:為專案範本分類,並且定義 [新增專案] 或 [加入新項目] 對話方塊的顯示特性。

  • TemplateContent:指定範本中所包含的檔案。

例如,下列程式碼呈現出一個專案範本的 .vstemplate 檔基本架構:

<VSTemplate Type="Project" Version="2.0.0"
    xmlns="https://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        ...
    </TemplateData>
    <TemplateContent>
        ...
    </TemplateContent>
</VSTemplate>

範本中繼資料檔是由 Visual Studio 隨附的 XML 結構描述進行驗證。 如需範本 XML 結構描述的詳細資訊,請參閱 Visual Studio 範本結構描述參考

進階項目

除了基礎的範本 XML 項目以外,您還可以使用 WizardExtensionWizardData 項目,將自動功能加入範本精靈 (此範本精靈可從範本建立新專案或新項目)。 您只需建立一個實作 IWizard 介面的組件並在 .vstemplate 檔中註冊此組件,就可以擁有自訂功能。 如需詳細資訊,請參閱 HOW TO:搭配專案範本使用精靈

基本專案範本 .vstemplate 檔

下列範例示範 Visual C# 專案的自訂範本。

<VSTemplate Type="Project" Version="2.0.0"
    xmlns="https://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>My template</Name>
        <Description>A basic template.</Description>
        <Icon>TemplateIcon.ico</Icon>
        <ProjectType>CSharp</ProjectType>
    </TemplateData>
    <TemplateContent>
        <Project File="MyTemplate.csproj">
            <ProjectItem>Form1.cs<ProjectItem>
            <ProjectItem>Form1.Designer.cs</ProjectItem>
            <ProjectItem>Properties\AssemblyInfo.cs</ProjectItem>
            <ProjectItem>Properties\Resources.resx</ProjectItem>
            <ProjectItem>Properties\Resources.Designer.cs</ProjectItem>
            <ProjectItem>Properties\Settings.settings</ProjectItem>
            <ProjectItem>Properties\Settings.Designer.cs</ProjectItem>
        </Project>
    </TemplateContent>
</VSTemplate>

請參閱

參考

Visual Studio 範本結構描述參考

其他資源

Visual Studio 範本

How to: Select the XML Schema(s) to Use for Validation