Compartir a través de


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 https://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.

Comments

  • Anonymous
    November 29, 2004
    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.

  • Anonymous
    November 29, 2004
    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>

  • Anonymous
    December 29, 2004
    This little tip saved me a helluva lot of work! Thank you!

  • Anonymous
    May 16, 2005
    Jomo Fisher--I mentioned a while ago that MSBuild team uses Test Driven Development (TDD). Afterwards,...

  • Anonymous
    May 25, 2005
    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.

  • Anonymous
    May 05, 2006
    The following links to .NET resources have been collated over time with the assistance of colleagues.&amp;nbsp;...

  • Anonymous
    October 25, 2006
    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?

  • Anonymous
    December 04, 2006
    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

  • Anonymous
    December 07, 2006
    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

  • Anonymous
    January 25, 2007
    I know this post is a litle old but hopefully someone is watching it. I do not agree. Go to http://www.autosjobs.info

  • Anonymous
    March 20, 2007
    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

  • Anonymous
    July 19, 2008
    PingBack from http://www19.a2hosting.com/~tarasn/devintelligence.com/?p=592