April 15, 2010
Migrating a C++/CLI Project to Visual Studio 2010
You’ve probably read that Visual Studio 2010 supports multi-targeting: with the flick of a project property switch, the compiler can generate binaries for either the .NET 3.5 or .NET 4 platforms. And in fact, when you upgrade a Visual Studio 2008 solution to 2010, the upgrader will set the target framework to 3.5 so that your code compiles and runs exactly as before. (New projects, by default, target .NET 4.)
However, this is only true for C# and VB projects; C++/CLI projects will automatically be upgraded to .NET 4 and the new VC10 compiler. It is possible to change this, but there is no UI1; you have to edit the project file manually. And, most importantly, Visual Studio 2008 SP1 must be installed side-by-side for this to work2. The VC10 compiler has no support for .NET 3.5, so Visual Studio will invoke the VC9 compiler (included in VS2008) if you target the .NET 3.5 platform.
To change the target framework3:
- Open the solution in VS2010 and have it convert the project files to the new VCXPROJ format.
- Close the solution, or manually unload the C++ project file.
- Open the VCXPROJ project file in a text editor.
- Find the XML element <PropertyGroup Label="Globals">
- Find the <TargetFrameworkVersion> child element; if not present add it.
- Set the inner text of the element to the desired framework version (v2.0, v3.0, v3.5, or v4.0), e.g.,
- Optional: Add <TargetFrameworkProfile>Client</TargetFrameworkProfile> if you want to target the client profile (or remove that element if it exists to target the full framework)4.
- Save the VCXPROJ file and close it.
- Reload the project/solution in Visual Studio 2010.
- There is UI for native-only projects; see Native Multi-Targeting at the Visual C++ Team Blog.
- See C++ Property Pages documentation at MSDN.
- Thanks to Đonny who provided excellent instructions in community content added to a MSDN article.
- Thanks to Rick Brewster at the Paint.NET Blog for this tip.
Posted by Bradley Grainger at April 15, 2010 9:25 AM
TrackBack URL for this entry: