Framework Multi-Targeting for VC++ Projects
Short Bio: Pavan Adharapurapu is a developer on the Visual Studio Project and Build team. As part of VS 2010, he has worked on numerous features of the VC++ project system such as property sheets, filters, property pages, platform and tool extensibility, etc. His long term focus is on developing a “common project system” infrastructure which could be used to quickly build richly featured project systems. Prior to joining the Visual Studio team in 2008, he was working on Workflow technologies in Microsoft Dynamics Axapta. Pavan holds a Masters degree in Computer Science (CS) from the University of California, Los Angeles (UCLA) and a Bachelors degree in CS from the Indian Institute of Technology (IIT), Madras. He lives in Redmond, WA with his wife and loves to play soccer and watch movies in his spare time.
Have you ever wanted to target .NET Framework 3.5 with your C++ application in Visual Studio 2010? If you’ve upgrade your C++ CLR application or created a new one, you will notice that it automatically will target .NET Framework 4.0. However, with a little bit of work it is possible to have your C++ CLR application developed in VS 2010 and targeting 3.5. This blog post will explain just that. Please note that this post is about managed re-targeting for VC++ projects as opposed to
· Managed re-targeting for C#/VB projects (see ScottGu’s blog post for this), or
I assume that you have a VS 2010 VC++ CLR project (.vcxproj) generated, perhaps, by the Visual Studio Conversion Wizard that you want to re-target to v3.5 framework version. Note that you can see the current framework version targeted by this project by going to the project properties UI and looking under Common Properties > Framework and References for the Targeted framework property (see snapshot below).
This field was a drop-down in VS 2008 and was the primary way one could re-target to a different framework version. In VS 2010, it is a read-only field. To re-target in VS 2010, we need to do some work.
First of all VS 2008 SP1 must be installed on your system (you cannot do without SP1). This is a mandatory requirement for targeting framework version 3.5. Installing only the .NET Framework 3.5 redist won’t do. C++ tools like cl.exe in VS 2010 are only capable of targeting v4.0. So to target an earlier framework version, we need the tools from that earlier version. And these tools are shipped with VS and not with .NET Framework.
Next, you need to manually edit the project file (.vcxproj) with a text editor (like notepad) and add the TargetFrameworkVersion property (if it is not already there) as shown below. It is recommended that this property be added to the property group labeled “Globals”.
If you use VS IDE itself to edit the project file (you have to first Unload Project and then choose Edit MyProject.vcxproj from the context menu of the project in the solution explorer), you will get the very helpful intellisense (see picture below) that will aid you in the definition of this property.
Once this property is defined with the right value, reload the project and verify that the Targeted framework property mentioned at the beginning of this post shows v3.5.