问题
I've been modifying the VS2010 item and project templates so each time we do a "new project" or "new item" we get it created in a format that works for us. This is all working fine; if we create a new class library we get it with the references we've set up and it doesn't create the "class1.cs" file - that all works. We've made a similar change to the TestProject.zip file that lives in:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033
Gone through the same process of zipping it back up, copying it over top of the original and refreshing the cache. However for the test project we can't stop it creating the default "unittest1.cs" file. All of our other changes to the test project are working fine but we just can't stop it creating the "unittest1.cs" file. It was never in the template or csproj file originally so I'm not sure what is creating it.
Can anyone help? What creates the default test file for the test project - I'm wondering if it's a reference to the wizard that is in the template file but have no idea what changes would be needed.
回答1:
- Close Visual Studio
Extract
BasicUnitTest.zip
from:C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\1033
Open
BasicUnitTest.vstemplate
Remove
<ProjectItem ReplaceParameters="true">UnitTest.cs</ProjectItem>
- Zip
BasicUnitTest.vstemplate
intoBasicUnitTest.zip
(excludingUnitTest.cs
) Go to:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\CSharp\1033
Delete
UnitTest.cs
and replaceBasicUnitTest.vstemplate
with your modified copy- On the next run of Visual Studio you should see the modified UnitTest
Though you can do this for every default template, I recommend creating a new template based on the BasicUnitTest.zip
instead of overriding the ones shipped with Visual Studio. It's easier, safer and won't be overwritten by future service packs.
来源:https://stackoverflow.com/questions/9435485/editing-testproject-zip-to-stop-unittest1-cs-being-created