While porting Paint.NET v3.5.5 to .NET 4, I naturally ran head-first into the problem of making sure my two C++/CLI assemblies were targeting the client profile and not requiring the full framework. The problem here is that Visual Studio 2010 does not have a UI for setting a C++/CLI assembly’s target framework version and profile.
On MSDN, I found that someone had added a note on how to target a non-v4 version of the framework by editing or adding a <TargetFrameworkVersion> element to the VCXPROJ file. Once I saw this, I looked as the CSPROJ files for my other assemblies to see how they did it, and they were using the same element with the same value in the same location. They also used an additional element to specify which profile (Client or Full) was targeted. On a whim, I decided to guess and check to see if this same element was honored by the C++/CLI compiler, and it is!
So here we go: (this is modified from the text already at the page linked to above)
To change the version and profile of the .NET Framework for C++/CLI projects (VS 2010)
1. Right click on project in Solution Explorer and click Unload project
2. Right click on unloaded project in Solution Explorer and select Edit <projectname>.vcxproj
3. In project XML file locate node <PropertyGroup Label=”Globals”>
4. In that node locate node <TargetFrameworkVersion> (if the node cannot be found, add it)
5. Inner text of the node defines target framework. It can be v2.0,v3.0, v3.5 or v4.0
6. In that node locate node <TargetFrameworkProfile> (if the node cannot be found, add it)
7. Inner text of the node defines the target framework profile. For the Client profile, set it to Client (for Full, just omit the element)
8. Save vcxproj file and close it
9. Right click on unloaded project in Solution Explorer and click Reload Project
<PropertyGroup Label="Globals"> … <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkProfile>Client</TargetFrameworkProfile> </PropertyGroup>
4 thoughts on “How to: Target .NET 4.0 Client Profile with C++/CLI”
wait, seriously? You can’t target previous versions of .net? That seems like a pretty big oversight.
Yes, you can. There’s just no UI for it, that I could find. Also, this only applies to C++/CLI, not to VB or C# which have a simple dropdown box for it.
You need to have the VC9 compiler (i.e., VS2008) installed to target previous versions of .NET. That’s why there’s no UI to change it: out of the box (on a brand new install), it wouldn’t work.
This reminds me of troubles we had ages ago while trying to add postbuilds to VB.NET (VS2003) projects… There was no UI in the VB project properties pages. And the same trick did work: copy/paste the tag from csproj to vbproj… it did work (tough the tag was removed each time you saved the project…). Hope you won’t experience the same thing with your vcxproj. Did you try adding a file to the project then saving it to check the was kept?
Comments are closed.