Thursday, February 25, 2010

A tool to switch project files between using Visual Studio 2008 and 2010

tool-boxUpdate: the source is now on GitHub

Visual Studio 2010 is almost here. Visual Studio 2010 (the release candidate) is here.

I’ll describe the problem before I describe the tool: You want to use the latest version of Visual Studio but you don’t want it to modify all of your projects and solutions because you’ve got other team members who don’t want to (or can’t) switch to 2010.

A serious problem indeed. If only you could you run a tool to update all of you project files to 2010, do your changes in Visual Studio 2010, then switch all projects back to 2008 format before checking in.

Well, here’s a command line tool to do just that!

It’s very easy to use: run it from the command line, give it a folder name, and tell it whether you want all your projects and solutions under that folder to be either 2008 or 2010 format. For example:

SwitchVsVersion c:\temp\MySolution 2010
SwitchVsVersion c:\temp\MySolution 2008

As a bonus, you can also tell it to change all your target frameworks to either .NET 4 or .NET 3.5. For example:

SwitchVsVersion c:\temp\MySolution 3.5Framework
SwitchVsVersion c:\temp\MySolution 4.0Framework

Binary here. Source code here. Here’s a test solution with lots of different empty projects to try it out on too.

Disclaimer: this is a noddy little tool that may not work properly on your projects and solutions. I’ve tested it on quite a large WinForms solution and it worked fine. I’ve also tested it on quite a variety of projects including C# and VB WinForms, Web Apps, Libraries, WPF Projects, and WPF Libraries. The only one it doesn’t do is C++ projects (which is a coincidence, because I no longer do C++ projects either). Be sure to back up your stuff before you use this tool! Terms and conditions apply.

Update: Thanks for the feedback. As requested, the source is covered under the WTFPL. Do what you want with it:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details.

9 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Richard Minerich said...

It would be awesome if someone wrote one of these that supported C++/CLI projects.

Englestone said...

Awesome!

Unknown said...

Can you post a license for the source so other people can use it? Ms-PL? BSD?

Joshua Flanagan said...

Thanks Steve. I've modified the source a bit to try and preserve file encoding.

http://github.com/joshuaflanagan/switchvsversion

sbohlen said...

First -- thanks for this, its (generally) awesome, nice work.

Second, wanted to share a 'gotcha' I ran into with anyone else using this tool:

If you take a VS2010 sln with projects explicitly targeting .NET 4.0 and try to move it to VS2008 using just "SwitchVSVersion 2008" (e.g., NOT also explicitly changing the target fwk version to '3.5' or earlier that VS2008 would understand, you get the following VERY hard to diagnose behavior out of VS2008:

1) the code ACTUALLY compiles just fine even thought the proj files still contain the '4.0' as the target framework version

2) VS2008 fails to actually DO the 'copy local=true' for any references that are set that way (though you get NO errors during the VS2008 build indicating that this isn't working for you!)

3) if you open the project properties and inspect the 'target framework' setting in VS2008, it will be BLANK because the VS2008 proj properties editor doesn't know what to do with 'target fwk=4.0' in the prop editor

This is NOT an issue if your target fwk version under VS2010 is already something understood by VS2008 (e.g., 3.5 or earlier) but if your VS2010 projects explicitly target fwk v4.0 you will experience this (hard to diagnose) behavior if you (accidentally) leave the target fwk set to 4.0 and try to work with the sln/projs under VS2008.

Not sure its the job of this util to solve this problem as its really just an error in my own application of the util, but wondering if it would be possible for the '2008' command-line arg to ALSO inspect the target fwk version and set anything where it = 4.0 to automatically be =3.5 so that others aren't also caught by this 'gotcha'.

As an example, after having run this successfully for some time in re: projs targeting fwk 3.5, I honestly thought it was 'broken' for some reason re: this solution b/c its projects were set to fwk 4.0 (thus I had the really hard to diagnose trouble with VS2008 when opening this solution in VS2008).

Hope this comment helps anyone else that might experience the same issue using this tool.

Joshua Flanagan said...

I've removed my git repo now that Steve has one. Get the latest from:

http://github.com/SteveDunn/SwitchVsVersion

Unknown said...

I don't have access to the binary - it's saying I don't have permissions. I tried to download the source, but its a VS2010 solution! Which I don't have, hence the reason I am looking for a converter :-)

Anonymous said...

You absolute god for writing this software! Saved my life!