Custom NAnt Task for Removing TFS Bindings

Published 21 May 08 07:46 AM | jacobl 

Before I get started, I want to say thanks to Mike Carbenay and his article on CodeProject about removing source control bindings. His WinForms app gave me the base which was used to develop this custom NAnt task.

Atalasoft is a toolkit vendor. So, as you can imagine, we develop loads of demos that we give to our customers showing off how to use different pieces of our products. Being the CI shop that we are, we keep all of our code in source control, namely Team Foundation Server. We have automated builds for everything from our core product to our internal systems to those demos that we deliver to customers. The problem lies in delivering the source code.

I'm not sure how VSS works in this case, but I am pretty sure that SVN and CVS don't store version control information in the actual project and solution files; however, TFS does. This proves problematic when putting those same source files into our toolkit installer. Sure, the projects open, but not without fuss. Visual Studio barks at you for having a source control system that it can't access. Makes sense, but it's annoying. This article will highlight a custom NAnt task that strips a folder of all source control bindings. Here's the task and here's the source, but read on if you want to know how it's all done.

How do I use this thing?

Using this task is trivial. Deploy it by following the instructions in my last blog entry about Custom NAnt tasks. After NAnt can see it, add the following line to your NAnt build script before your build target:

<removetfsbindings dir="${pathToYourSourceTree}" />

That's it. It will recursively move through the directory you provided and remove all source control binding-related information.

How it all works...

What needs to happen here?

The first thing we need to do is figure out what we need to remove. I've attached a project that has source control bindings so you can test your task with it. Download it and poke around the file structure a bit. There are some files in there that will need to be removed: anything ending in vssscc and anything ending in vspscc. Make not of them because when we get to writing the script, we'll need to remove those too.

Next, open the solution file in Notepad so we can see exactly what we need to rip out of there too. After a little bit of poking around, you will notice the GlobalSection(TeamFoundationVersionControl) block. This entire area is what's pointing at source control and it must go!

Finally, open the project file and you'll notice elements that have names starting with "Scc". These must go as well. If we want to support Visual Studio 2003 projects and their respective bindings to source control, it is slightly different. In the project files, there are no elements that start with "Scc", but attributes of elements instead. So simply remove all elements and attributes that start with Scc and you should be good.

Not getting into the code

To learn how to write a custom NAnt task, read my blog post about doing just that

This task is fairly straight forward to follow in the source so I'm not going to step through it here. Just download it and if you have any questions, drop me a note. There is one section that I had to add when writing back the project file. For some reason, Visual Studio 2005 doesn't like projects that start with an xml declaration:

<?xml ...

and the .NET XmlTextWriter object pushes that out on its own when writing to a file. The workaround was adapted from Ben Cops blog article about tricking the XmlTextWriter into thinking it already wrote the declaration. Thanks Ben!

Making this really useful.

This task is very useful as it is, but the only thing that would make it even better for a company who turns out 30+ demos and needs to make sure they are all binding-free is to make it work on complete folder hierarchies. The task recursively travels through the folder hierarchy and removes all bindings and binding-related files for Visual Studio 2003, 2005, and 2008 projects.

Enjoy!

You'll have to download NAnt as described in my blog about writing custom NAnt tasks. After you've done that, you can add a reference to NAnt.Core.dll to this project.

Download the Source | Download the Assembly | Download the Test Project
Filed under: , , ,

Comments

# DotNetKicks.com said on May 21, 2008 12:11 PM:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Anonymous comments are disabled