In this blog post, I’ll explain the possibilities and limitations of using solutions and projects between Visual Studio 2005 and 2008. Read on!
The upcoming release of Visual Studio 2008 introduces a great new feature called ”.NET Framework Multi-targeting” that allows you to target multiple versions of the .NET framework using Visual Studio 2008. (Check out Luke Hoban’s blog and Scott Guthrie’s blog for additional information) Multi-targeting opens up a new world of possibilities, in addition to its fair share of questions. One particular question that we’ve been hearing often over the past few months is: “How can I work with solutions and projects between Visual Studio 2005 and Visual Studio 2008?”.
The short answer to this question is:
- Solutions created in Visual Studio 2008 cannot be opened in Visual Studio 2005
- Projects created in Visual Studio 2008 can be opened in Visual Studio 2005
- Solutions and projects created in Visual Studio 2005 can be opened in Visual Studio 2008
As with all things, there are some subtle details with these statements that I’d like to take some time to explore with you.
Solutions created in VS2008 cannot be opened in VS2005
As you work with multi-targeting, you or your team may have a need to share solutions between Visual Studio 2005 and Visual Studio 2008. One common scenario would be opening a solution created in Visual Studio 2008 and targeting .NET Framework 2.0 in Visual Studio 2005. You’ll find that opening this solution in Visual Studio 2005 will give you the following error dialog.
Diagram 1: Error message when opening VS2008 solution in VS2005
This dialog demonstrates an important point: Opening Visual Studio 2008 solutions in Visual Studio 2005 is not supported at the solution level. This is triggered by the fact that the version number in the .sln file of any solution created in or upgraded to Visual Studio 2008 has been updated to 10.00 (see Diagram 2). This was a tough decision that we had to take during the design of Visual Studio 2008 and was due to the enormous complexity and cost of supporting the resulting compatibility scenarios. This is an area that we will be actively investigating to improve for our next release.
|Visual Studio 2005||Visual Studio 2008|
Microsoft Visual Studio Solution File, Format Version 9.00
Microsoft Visual Studio Solution File, Format Version 10.00
Diagram 2: Comparison of .sln files between VS2005 and VS2008
Are there any workarounds?
If you’re daring, there are a few things that you can do to work around this restriction. Given that these scenarios are not supported, going down these routes may cause your project items to become corrupt, designer elements to break, etc. so please keep these risks in mind.
The first workaround is a rather obvious one that you may have already tried. It involves modifying the version of the Visual Studio 2008 .sln file to 9.00. You’ll find that in most cases, this will do the trick and allow Visual Studio 2005 to open the solution. However, if the solution contains any projects and/or settings that are new to Visual Studio 2008 (i.e. usage of new language constructs, designer interfaces, etc.), the solution can fall apart. I would encourage you to not use this workaround, especially for solutions that contain several projects.
The second work around involves adding projects created in Visual Studio 2008 directly into an existing Visual Studio 2005 solution. The important point to note here is that Visual Studio 2008 projects are not explicitly blocked from being opened/added to Visual Studio 2005 solutions. The motivation behind this decision was to ensure that Visual Studio would remain performant by avoiding the performance hit of checking the versioning of every single project in a solution on startup. This workaround has similar risks as the first workaround, but given that it forces you to make a targeted decision as to which project to use in the Visual Studio 2005 solution, it may be a viable workaround for you.
A note about the ToolsVersion attribute
For both of the workarounds above, you can update the project files (.csproj, .vbproj, etc.) to control the version of the build tools that will be used. This is done through the ToolsVersion attribute on the Project element. Diagram 3 describes the change that needs to be made in order for a project created in Visual Studio 2008 to invoke the 2.0 version of the build tools.
|Original .csproj||Modified .csproj|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns= "http://schemas.microsoft.com/
<Project ToolsVersion="2.0" DefaultTargets="Build" xmlns= "http://schemas.microsoft.com/
Solutions and projects created in VS2005 can be opened in VS2008
It's worth mentioning that when opening a Visual Studio 2005 solution or project in Visual Studio 2008, you will see a dialog that will guide you through the upgrade process. The important thing to keep in mind is that this process will update the version number in the .sln file to 10.00, which will prevent this solution from being opened again in Visual Studio 2005. Note that all of the points discussed in this post apply to these upgraded solutions and projects as well.
As always, I’d love to hear your feedback and questions. I expect there to be some confusion on this topic so feel free to add your comments. Also, if you happen to run into any issues while trying out different scenarios involving solution/project inter-operability between Visual Studio 2005 and 2008, file a bug on the Connect website.