Welcome to MSDN Blogs Sign in | Join | Help

Hack the Build: Programmatically Converting Older VS .NET Projects to MSBuild

Jomo Fisher--There are plenty of reasons you might want to programmatically convert projects from VS .NET 2003 format to MSBuild format. Maybe you have a bunch of old .csproj files and you'd like to convert them in batch. Maybe you'd like to keep your projects in VS7 format and convert them to MSBuild format on the fly. These are definitely Hack-the-Build-worthy pursuits, so let's dig in.

 

MSBuild ships with an assembly called Microsoft.Build.Conversion.dll which contains the code that Visual Studio .NET 2005 uses to convert older C# and VB projects into MSBuild format (unfortunately C++ is not supported).

 

The code for calling this API is so simple, I can paste it right here:

 

/*

Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

Written by Jomo Fisher

*/

 

using System;

using System.Text;

using Microsoft.Build.Conversion;

 

class ConvertProject

{

     static void Main(string[] args)

     {

          ProjectFileConverter c =

           new ProjectFileConverter();

          c.OldProjectFile = args[0];

          c.NewProjectFile = args[1];

 

          c.Convert();

     }

}

 

To invoke, just call the code with source and destination file names:

 

   ConvertProject VS7.csproj VS8.csproj

 

A few things to note:

·        You'll need to add a reference to Microsoft.Build.Conversion in your project.

·        You'll need to manually copy the DLL Microsoft.Build.Conversion.dll into the same directory as the application built from the code above. Chances are that we'll have this DLL in the GAC for the next Beta, but for now you'll just need to manually copy it.

·        This API is undocumented and not supported for calling directly. Caveat emptor, etc.

 

If you subscribe to other Microsoft Visual Studio related blogs you may have noticed a lull in the postings. This is because we're working like caffeinated woodpeckers getting the next Beta of VS ready. Thankfully, the tryptophan has cut through my (legal) stimulant haze long enough this morning to allow me to post a hack for you—I hope you find it worthy.

 

One thing worth mentioning as we head down the homestretch: We've used Test Driven Development with NUnit throughout most of the MSBuild development cycle. We're really seeing a big pay-off in the end-game--we're able to make difficult changes in complex code with confidence that we're not breaking functionality. In other words, I've tasted the Kool-Aid and can only say “Oh, Yeaahh!”.

 

This posting is provided "AS IS" with no warranties, and confers no rights.

 

Published Monday, November 29, 2004 1:42 PM by Jomo Fisher
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# How to convert older VS .NET projects to MSBuild

Monday, November 29, 2004 2:50 PM by .Net Adventures

# re: Hack the Build: Converting Older VS .NET Projects to MSBuild

Since you mentioned it, could you talk a little about how you use NUnit to test. My company is looking into changing some of our methodologies and TDD has come up as the last best hope ;-). If not I'll understand, but I just think a lot of people are interested in how MSFT does the things it does.
Monday, November 29, 2004 2:54 PM by Lonnie McCullough

# re: Hack the Build: Converting Older VS .NET Projects to MSBuild

Great! It seem to be the right way to resolve my problems. Today I'll try to code it into my project. Thank you Jomo! <br>
Tuesday, November 30, 2004 3:12 AM by Lorenzo

# re: Hack the Build: Programmatically Converting Older VS .NET Projects to MSBuild

This little tip saved me a helluva lot of work! Thank you!
Wednesday, December 29, 2004 12:47 PM by Leo Duran

# How to convert older VS .NET projects to MSBuild

Wednesday, January 19, 2005 2:37 AM by .Net Adventures

# Hack the Build: Code Quality and Test Driven Development at Microsoft

Jomo Fisher--I mentioned a while ago that MSBuild team uses Test Driven Development (TDD). Afterwards,...
Monday, May 16, 2005 1:13 PM by Hack the Build

# Hack the Build: Use the Whole Test-First Whale

I don’t think of Test Driven Development as just a goal in itself. I think of it as a platform for a set of code-quality drivers. What follows is a set of ideas for how to wring the maximum use out of your developer-written tests.
Wednesday, May 25, 2005 2:01 PM by Hack the Build

# .NET Resources

The following links to .NET resources have been collated over time with the assistance of colleagues.&amp;nbsp;...
Saturday, May 06, 2006 4:31 AM by mattonsoftware.com

# re: Hack the Build: Programmatically Converting Older VS .NET Projects to MSBuild

I know this post is a litle old but hopefully someone is watching it.

Is there any way to go backwards?  from a VS8 format to a VS7?  I have a funky requirement where we need to do this.

Any ideas?

Wednesday, October 25, 2006 5:03 PM by Kyle Finley

# dissimilate Burgos

I know this post is a litle old but hopefully someone is watching it.

I do not agree. Go to http://www.hotelsclub.info/swag_Spain/cue_Castilla%20y%20Le%C3%B3n/dissimilate_Burgos_1.html

Monday, December 04, 2006 9:14 PM by dissimilate Burgos

# indirect Rome

I know this post is a litle old but hopefully someone is watching it.

I do not agree. Go to http://www.frhotelweb.info/invoke_Italy/garner_Lazio/indirect_Rome_1.html

Thursday, December 07, 2006 6:10 PM by indirect Rome

# Freiburg Jobs

I know this post is a litle old but hopefully someone is watching it.

I do not agree. Go to http://www.autosjobs.info

Thursday, January 25, 2007 11:05 AM by Strasbourg Jobs

# floreated Hannover

I know this post is a litle old but hopefully someone is watching it.

I do not agree. Go to http://www.cybercareers.info/imbecile_Germany/presence_Niedersachsen/floreated_Hannover_1.html

Wednesday, March 21, 2007 7:43 AM by floreated Hannover

# How to convert older VS .NET projects to MSBuild | devintelligence.com

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker