VS Project Assistant
After I was fed up with editing my project files in notepad all the time to synchronize
changes between different projects and inserting the
element in all my unit tests, I decided to write a small utility that aids me in these menial
project maintenance tasks.
The result of this work is pass – short for “project assistant”. Maybe other developers can benefit from this tool as well, so here goes:
Collating Project Nodes
A nice feature of the Visual Studio IDE is that it can display files as if they were sub-nodes of another file. You can see this feature in action when you create a Form or a Control:
This feature is a generic one. You can make any file become a subnode of another file. This is
a trick many people are already using to better organize their unit tests and partial classes.
Normally, it would involve adding a
<DedendentUpon /> element under the
<File /> node in your
.csproj file with notepad.
Using the ‘collate’ command, pass will turn any files beginning with the same name as another file into subnodes of that file.
Simply invoke pass like this:
pass collate MyProject.csproj
…and your unit tests and other nested files will be arranged automatically. You can even integrate this as an “External Tool” in Visual Studio.
Copying Project Filelists
XNA provides a built-in feature that keeps .csproj files in sync with each other. However, if one of the projects is not an XNA project (for example, when you’re using a plain class library in your XNA game), this mechanism can’t be used. Pass has also proven useful at work, where I can easily update the file list of special .NET Compact Framework .csproj files.
If you had a
MyProject (x86).csproj and wanted to take over the files added to that
project file into another project file called
MyProject (XBox 360).csproj, just
invoke pass like this:
pass copy "MyProject (x86).csproj" "MyProject (XBox 360).csproj"
Pass will do its best to keep the layout of the
.csproj file intact. It first
scans the source project for <ItemGroup /> nodes containing
<Compile /> nodes and then does the same for the target project, only that
this time, it will replace the contents of those
<ItemGroup /> nodes with
the ones from the source project. If the target project has more
<ItemGroup /> nodes, the additional nodes will be removed. If it has less,
<ItemGroup /> nodes will be created.
Sorry about the file size! The actual executable is only 14 KiB, but I have included NUnit 2.5 binaries for .NET 2.0 and Mono 2.0 so you can compile it out-of-the-box even when you don’t have NUnit installed 😉