VS模板不复制未在解决方案资源管理器中显示的文件

3
Visual Studio 2013。我创建自己的模板。
它的 vstemplate 文件有以下记录:
<Folder Name="batch-build" TargetFolderName="batch-build">
  <ProjectItem ReplaceParameters="true" TargetFileName="1_debug-build-all-versions.bat">
  <ProjectItem ReplaceParameters="true" TargetFileName="2_debug-build-all-versions-with-Gallio-tests.bat">
  <ProjectItem ReplaceParameters="true" TargetFileName="3_debug-build-all-versions-with-NUnit-tests.bat">
  <ProjectItem ReplaceParameters="true" TargetFileName="4_release-build-all-versions.bat">
</Folder>

我希望您能将所有这些文件复制到基于此模板的新项目中。但是此模板的 csproj 文件有一些限制条件:
<ItemGroup>
  <None Include="batch-build\1_debug-build-all-versions.bat" />
  <None Include="batch-build\4_release-build-all-versions.bat" />
</ItemGroup>

<Choose>
  <When Condition="'$(Build_With_Tests_Of)' == 'NUnit'">
    <ItemGroup>
      <None Include="batch-build\3_debug-build-all-versions-with-NUnit-tests.bat" />
    </ItemGroup>
  </When>
  <When Condition="'$(Build_With_Tests_Of)' == 'Gallio'">
    <ItemGroup>
      <None Include="batch-build\2_debug-build-all-versions-with-Gallio-tests.bat" />
    </ItemGroup>
  </When>
</Choose>

当创建一个新项目时,默认情况下Build_With_Tests_Of属性的值为Gallio。因此,在Solution Explorer中会显示batch-build\2_debug-build-all-versions-with-Gallio-tests.bat文件,这正是我所需要的。但是,如果我打开新项目的目录,我会发现batch-build\3_debug-build-all-versions-with-NUnit-tests.bat文件没有被复制。因此,模板不会复制在Solution Explorer中未显示的文件。但是我需要这些文件的完整副本。
如何强制模板复制所有文件?

仍然在15.8.2版本中存在这个问题。将文件设置为资源也没有帮助。 - Creepin
1个回答

3
我遇到了同样的问题。这是我的解决方案:
将所需文件添加到解决方案中。在其属性选项卡中,将其标记为资源。现在,创建您的模板。
将文件更改为资源将使模板复制该文件(假设您没有在首次包含它的解决方案中包含它,因为它不应被编译)。
希望这可以帮助你,这是我用于在模板项目中包含AssemblyInfo_Template.cs文件的解决方案。 (AssemblyInfo_Template.cs由SubWCRev.exe使用以覆盖AssemblyInfo.cs,以便在AssemblyInfo.cs中包含修订号)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接