I will assume that you are somewhat familiar with the Visual Studio environment and that you already know how to create Solutions and Projects. For these and other walkthroughs please refer to the Samples and Walkthroughs pages in MSDN.
The testing templates in Visual Studio 2005 are nothing more than extensions to the environment. In order to create a complete extension you would need to use the Visual Studio SDK. Creating a full Visual Studio extension is beyond the scope of this post.
With the help from Sarah Cameron, one of my colleagues at work, we have polished and divided the process into three main steps.
Create the Template
1. Start with the existing Manual Test template that can be found in your Visual Studio's Item Template folder. In my installation the path is D:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033. The template file name is ManualTestWordFormat.zip.
Note: In Visual Studio 2008 the above path would be D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\1033. The template file name is the same. The path varies from Microsoft Visual Studio 8 to Microsoft Visual Studio 9.0.
2. Create a folder that will contain your customized template files. In this example, I will call the folder InCycleManualTest. This will serve as a staging area and is really optional.
3. Extract the contents of the ManualTestWordFormat.zip into the InCycleManualTest folder. The folder should now contain two files: ManualTest.mht and ManualTest.vstemplate.
4. Rename both extracted files to match the name of your template folder. In this example, the files are renamed to InCycleManualTest.mht and InCycleManualTest.vstemplate, respectively.
5. Open the .mht file in Microsoft Word and modify the document to suit your needs. When you are done you can save the document and close Word. You now have the document template contents for your customized Manual Test.
6. Open the file .vstemplate in a text editor such as Notepad. You should see the contents as an XML-formatted document. The document looks like the following.
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<Name Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="113"/>
<Description Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="109"/>
<Icon Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="107"/>
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<DefaultName>ManualTest.mht</DefaultName>
<TemplateGroupID>TestProject-V1</TemplateGroupID>
<TemplateID>TestProject-V1-WordManualTest</TemplateID>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="false" OpenInEditor="true">ManualTest.mht</ProjectItem>
</TemplateContent>
<TestProjectData>
<LongDescription Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="112"/>
<Helpkeyword Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="105"/>
</TestProjectData>
<WizardExtension>
<Assembly>Microsoft.VisualStudio.QualityTools.Wizard.TestProjectWizards</Assembly>
<FullClassName>Microsoft.VisualStudio.TestTools.TestProjectWizards.TestItemWizardExtension</FullClassName>
</WizardExtension>
</VSTemplate>
Note: In Visual Studio 2008, the Version of the VSTemplate is 3.0.0. If you start with the template from the correct folder you will already have this version set correctly.
At this point the document represents the Manual Test Word format item template. We need to make some changes to add our customized template specific information.
Specifically update the following tags: Name, Description, DefaultName, TemplateID, and ProjectItem. Remove or replace the contents of the TestProjectData tag.
Save the document.
Note: It is very important that the TemplateID is unique. If it matches an existing template it will override its associated document.
Note: If you want to use special characters in the Name or Description of the template you will need to use the equivalent escape character (same XML rules apply to the .vstemplate document). For example, if you want to include a word that contains the French character "é" (no quotes) then you will need to replace it with its equivalent escape character "é" (no quotes). Failing to do so will cause the template to fail registration without any error message.
The following is the resulting InCycleManualTest.vstemplate file used in this example.
<VSTemplate Version="2.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>InCycle Manual Test (Word format)</Name>
<Description>Customized manual template</Description>
<Icon Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="107"/>
<ProjectType>CSharp</ProjectType>
<SortOrder>80</SortOrder>
<DefaultName>InCycleManualTest.mht</DefaultName>
<TemplateGroupID>TestProject-V1</TemplateGroupID>
<TemplateID>InCycleManualTest</TemplateID>
<ShowByDefault>false</ShowByDefault>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true" OpenInEditor="false">InCycleManualTest.mht</ProjectItem>
</TemplateContent>
<WizardExtension>
<Assembly>Microsoft.VisualStudio.QualityTools.Wizard.TestProjectWizards</Assembly>
<FullClassName>Microsoft.VisualStudio.TestTools.TestProjectWizards.TestItemWizardExtension</FullClassName>
</WizardExtension>
</VSTemplate>
7. Repackage the files you previously extracted and modified into a zip file and call it the same name as the folder you created. In this example, the compressed file is called IncycleManualTest.zip. Verify that the zip file does contain your two files and that these files do have your changes.
Note: It is very important that the files reside in the root of the zip file. If not, the template will not register correctly.
Deploy the Template
8. Copy the modified exported template zip file to your Visual Studio's Item Template folder. In this example, I copy the file IncycleManualTest.zip to my folder D:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033.
9. If updating an existing template you must first remove any previous template from Visual Studio’s Item Template Cache, which gets copied during the initial installation.
For example, if updating the IncycleManualTest.zip template I would remove the corresponding IncycleManualTest.zip file from my folder D:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache\CSharp\1033 before installing the new template. This is to ensure the new template is correctly updated in the cache.
10. Install your customized template. For the template installation command to work correctly you need to run the Visual Studio 2005 Command Prompt, as it initializes some environment variables required for the execution of the command.
The Visual Studio 2005 Command Prompt can be found under your Start menu. Look for the program group Microsoft Visual Studio 2005 / Visual Studio Tools. Launch it.
At this point, make sure you close any running instances of Visual Studio. At the command prompt type and execute the command devenv /InstallVSTemplates.
Give it some time to complete. Note that even after the command prompt returns your hard disk may continue spinning. So, give it some more time to make sure the registration is finalized.
Test the Template
11. Test your new template. Launch Visual Studio and open/create a Test Project. Select New Test... like you did before to display the Add New Test dialog. You should now see your new Manual Test template.
In order to do a complete test of this template you should create multiple Manual Test using it and go through the paces to make sure the template is recognized in the Test View.