posted on Friday, June 10, 2005 4:57 AM
by
Simon Thorneycroft
VS.NET custom projects...
Test driven development is a great way to deliver solutions, constantly giving you the confidence to add a piece of functionality or perform that next large refactoring. But setting up your project can be a real pain, at least two projects are required - the test assembly and the assembly under test - plus a bundle of references to NUnit, so I use a custom project wizard for VS .NET 2003 to do these painfully boring tasks for me. Tools for generating code and performing mundane tasks should always be encouraged; they allow you to get on with the stuff you enjoy without breaking your train of thought. If you don’t believe me then you need to read ‘The Pragmatic Programmer’! So, here is the approach to produce a simplified version of one of the wizards I use for my projects.
- Fire up notepad and create a ProjectAndTests.vsdir file that is located in your program files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjects, these files contain a lot of stuff that you just do not need to understand (perhaps I will go into detail in a later post). Okay, Add the following single line to your blank file:
CSharpDLLWithTest.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|Class Library And Test|1|Class Library and Test Template|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4547| |ClassLibraryWithTestProject
This gives VS the information it needs to display your project in the C# projects section.
- Now you need to create the vsz file that you just referred to. In the spirit of doing the least that works (XP), open the CSharpDLL.vsz file from this directory and change the line that says Param="WIZARD_NAME = CSharpDLLWiz" to Param="WIZARD_NAME = CSharpDLLWithTestWiz". Save this file as CSharpDLLWithTestWiz.vsz so VS now knows where your template should be.
- Go up one directory and then navigate to the VC#Wizards subdirectory. Make a copy of the CSharpDLLWiz folder with its contents and place it at the same level renamed as CSharpDLLWithTestWiz. The same name as that used in the previous step.
- Almost there, now we navigate into the CSharpDLLWithTestWiz\scripts\1033 directory, open the default.js file in there and make a couple of changes. cut the lines between:
var strProjectName = wizard.FindSymbol("PROJECT_NAME");
and
proj.Save();
exclusive and move them to a function:
function CreateProject(strProjectPath, strProjectName) { ... } add a final line to this function to return the proj instance (return proj;). now replace the empty space where you just cut from with two calls to your new function:
proj = CreateProject(strProjectPath + "Test", strProjectName + "Test");
var refmanager = GetCSharpReferenceManager(proj);
refmanager.Add(path to your nunit dll minus the extension here);
proj.Save();
proj = CreateProject(strProjectPath, strProjectName);
//the following line should be the proj.Save(); line that you had left from the original.
Save the file and close it.
- You’re done, fire up a fresh instance of VS.NET 2003 and create your new DLL with test project.
That’s it, this has been a bit of a whirlwind tour although the steps are about as simple as I could think of making them. I hope this helps you to begin automating away some of the pain in your development. If you get stuck, just email me at simon.thorneycroft@syncadia.com.