2016-08-03 152 views
0

我想爲Visual Studio 2013自定義UnitTest項目模板:我們經常在UnitTest項目中使用Moq,因此我認爲它應該被自動引用。Visual Studio 2013項目模板定製

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到該文件夾​​,並通過加入

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

編輯UnitTestProject.vstemplate到項目部分。

但是,當我創建一個新的單元測試項目中,我得到錯誤信息

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

除了更改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)時,該文件丟失,而對項目進行的所有其他更改(構建後操作,引用等)均被應用。