【问题标题】:Visual Studio 2013 Project Template CustomizationVisual Studio 2013 项目模板自定义
【发布时间】:2016-08-03 09:59:26
【问题描述】:

我想为 Visual Studio 2013 自定义 UnitTest 项目模板:我们在 UnitTest 项目中经常使用 Moq,因此我认为应该自动引用它。

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033\UnitTestProject 中,我通过添加参考部分和ItemGroup 编辑了UnitTestProject.csproj

<ItemGroup>
    <None Include="packages.config" />
</ItemGroup>
...
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
  <HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
  <Private>True</Private>
</Reference>

然后我将文件 packages.config 添加到该文件夹​​,并通过添加编辑UnitTestProject.vstemplate

<ProjectItem ReplaceParameters="false" TargetFileName="packages.config">packages.config</ProjectItem>

到项目部分。

但是当我创建一个新的 UnitTest 项目时,我收到了错误消息

The file packages.config could not be found within the project templates. Continuing to run, but the resulting project may not build properly.

点击确定后,出现另一条错误信息:

Unable to copy the file 'packages.config' from the project template to the project. Cannot find file "(%TEMP%\some folder)\packages.config'.

如何解决?

【问题讨论】:

    标签: visual-studio visual-studio-2013 project-template


    【解决方案1】:

    除了更改C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates 中的模板之外,我还必须在C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplatesCache 中替换它。接下来,我必须查看 %AppData%\C:\Users\bernhard.hiller\AppData\Roaming\Microsoft\VisualStudio\12.0\ProjectTemplatesCache 并删除模板的 zip 文件。

    现在,当我手动添加新的单元测试项目时,packages.config 文件会被复制。但是当使用“单元测试生成器”(参见https://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7)时,该文件会丢失,而对项目的所有其他更改(构建后操作、引用等)都已应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 2019-03-20
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      相关资源
      最近更新 更多