File referenced by ProjectItem is not created when new Project created

时间:2019-01-18 18:56:42

标签: visual-studio project-template projectitem

Trying to create my first Project Template for a simple VS2015 C# project. But when I try to create a Project with it, one of the files - post_build.bat - is missing.

The content of the project template ZIP file is:

    AssemblyInfo.cs
    Class1.cs
    ImsProject.ico
    ImsProject.vstemplate
    post_build.bat
    ProjectTemplate.csproj

The ImsProject.vstemplate file contains the following TemplateContent:

      <TemplateContent>
        <Project File="ProjectTemplate.csproj" ReplaceParameters="true">
          <ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
          <ProjectItem ReplaceParameters="true" OpenInEditor="true">Class1.cs</ProjectItem>
          <ProjectItem>post_build.bat</ProjectItem>
        </Project>
      </TemplateContent>

Seems simple, but I must be doing something wrong.

1 个答案:

答案 0 :(得分:0)

愚蠢的我!

我以为不存在post_build.bat文件是因为创建新项目时,它没有出现在Visual Studio的解决方案资源管理器中。

但是...它存在于包含新项目的文件夹中。

问题是我没有在ProjectTemplate.csproj文件的ItemGroup中创建条目。

添加

    <ItemGroup>
        <None Include="post_build.bat" />
    </ItemGroup>

解决了问题