專案項目 (Visual Studio 範本)

指定要加入至專案的檔案或目錄。

<Project
    File="MyProject.proj"
    TargetFileName="MyTargetProject.proj"
    ReplaceParameters="true/false">
        ...
</Project>

屬性和項目

下列小節將說明屬性、子項目和父項目。

屬性

屬性

說明

File

必要屬性。

指定範本檔 (.zip) 中的專案檔名稱。

ReplaceParameters

選擇性屬性。

布林值,指定專案檔是否具有當您從範本建立專案時必須取代的參數值。 預設值為 false。

TargetFileName

選擇性屬性。

當您從範本建立專案時,指定專案檔名稱。

子項目

項目

說明

資料夾

選擇性項目。

指定要加入至專案的資料夾。

ProjectItem

選擇性項目。

指定要加入至專案的檔案。

父項目

項目

說明

TemplateContent

必要項目。

備註

ProjectTemplateContent 的選擇性子項目。

Project 項目用來指定專案,因此只在專案範本中有效。

Project 項目可以擁有 Folder 子項目或 ProjectItem 子項目,但不能同時擁有 Folder 子項目和 ProjectItem 子項目。

Visual Studio 會根據使用者在 [新增專案] 對話方塊中輸入的名稱,自動重新命名專案檔名。 如果您想要為使用範本而建立的專案檔提供另一個替代檔名,請使用 TargetFileName 屬性 (Attribute)。

範例

下列程式碼範例會示範 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 starter kit</Description>
        <Icon>TemplateIcon.ico</Icon>
        <ProjectType>CSharp</ProjectType>
    </TemplateData>
    <TemplateContent>
        <Project File="MyStarterKit.csproj">
            <ProjectItem>Form1.cs<ProjectItem>
            <ProjectItem>Form1.Designer.cs</ProjectItem>
            <ProjectItem>Program.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 範本結構描述參考

ProjectItem 項目 (Visual Studio 專案範本)

資料夾項目 (Visual Studio 專案範本)

概念

專案範本與項目範本之間的差異

其他資源

Visual Studio 範本