Search code examples
visual-studio-2010project-template

Editing "testproject.zip" to stop "UnitTest1.cs" being created


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.


Solution

    1. Close Visual Studio
    2. Extract BasicUnitTest.zip from:

      C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\1033

    3. Open BasicUnitTest.vstemplate

    4. Remove <ProjectItem ReplaceParameters="true">UnitTest.cs</ProjectItem>

    5. Zip BasicUnitTest.vstemplate into BasicUnitTest.zip (excluding UnitTest.cs)
    6. Go to:

      C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\CSharp\1033

    7. Delete UnitTest.cs and replace BasicUnitTest.vstemplate with your modified copy

    8. 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.