我想为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'.
如何解决?
答案 0 :(得分:0)
除了更改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)时,在应用项目的所有其他更改(后构建操作,引用,...)时,此文件丢失。