VS2012 CLR project target framwork v3.5 RRS feed

  • Question

  • Hi all,

    I was experimenting with VS2012 on how well it supports C++/CLI targetting the different versions of .NET.

    It seems like it can perfectly well create C++/CLI projects for .NET v4.0 and .NET v.4.5. 
    So i was hoping it would also support .NET v3.5 (VS2010 is unable to do this with its intended toolset vc100).

    And this is where the strange things start. From first glance both the project settings UI as the vcxproj files nicely show TargetFrameworkVersion v3.5 and referencing CLR 2.0 assemblies (system, system.data and system.xml).
    However, when compiling the project, it somehow found it necessary to not only add references to add a reference to mscorlib (needed ofcourse), but also add references to system and mscorlib This obviously defeats the purpose of providing option to target anything below .NET 4.0, since other .NET projects need to target at least 4.0 to even reference the library.
    Is this behavior by design?

    Has anyone else experienced the same problem? If so, how to solve this (if possible).

    I'm using VS2012 Premium Update 1.

    Friday, January 11, 2013 1:49 PM

All replies

  • Publish the application and then install on 3.5 machine.  The publish will install missing dll needed to run on 3.5


    Friday, January 11, 2013 5:08 PM
  • It seems impossible.

    The methods name is the same between 2.0 and 4.0, if you add both assemblies, the compiler will not decide to use which one.

    Have a nice day,

    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Monday, January 14, 2013 10:12 AM
  • @Joel
    if I would want .NET 4.0, i would target .NET 4.0 to start with. The reason we want .NET 3.5 is that it is available by default on almost all of our customers pc's. We deploy using ClickOnce, which doesnt require elevated priveleges as long the needed framework is available already.
    And to make things worse, VisualStudio doesn't allow to reference that specific CLR project from a .NET 3.5 project, due to the references to .NET 4.0 that the compiler added.

    I think you are right, and it's impossible to target .NET 3.5 with the vc110 toolset. Like you say, having both versions referenced is very bad. Hence my surprise that VS2012 actually doesn't complain in any way when compiling the C++ CLR project with vc110, targetting .NET 3.5, it will not ever work correctly. I was hoping someone would be able to shed some light on this.

    • Edited by Laibalion Wednesday, January 16, 2013 9:45 PM
    Wednesday, January 16, 2013 9:42 PM
  • Hi Laibalion,

    So how about ask this in C++ forum? Maybe that guys know what happened.

    Have a nice day.

    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Thursday, January 17, 2013 2:47 AM
  • The Net Library struture is complicated.  You have 1.0, 2.0, 3.0, 3.5, 4.0, and 4.5.  The newer libraries only contain new methods or upgrades to methods in older library that isn't backwards/forward compatible.  You also can't an older version of the library if a function you are using is not available.

    Before targeting to an older version the Net Library make sure you rebuild the entire project and any reference projects.  I normally like to delete the entire bin and obj folders to make sure everything get fully compiled.  VS will automatically recreate the bin and obj folders if they are deleted.


    • Proposed as answer by CrazyGhost_Von Friday, January 18, 2013 2:41 AM
    Thursday, January 17, 2013 10:19 AM
  • Agree with Joel :)

    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Friday, January 18, 2013 2:41 AM
  • @Joel:

    I know that the library structure is complicated, I'm not new to this.
    However, for some of our products it is desirable to target .NET 3.5 and up till now we do this by using VS2008 with an old branch of our C++ backend. However, we want to let them start using the current version of the C++ backend, which is using some c++0x features already, so VS2008 won't do the trick anymore.

    So i started investigating if VS2012 can target different version of .NET, including .NET 3.5. .NET 4.0 and 4.5 are possible and it works fine. However, VS2012 allows you to target .NET3.5 for a CLR project as well, and then the problems start (as described in my opening post).

    I'm not upgrading projects etc, my investigation was with newly created projects. You can find sample code for the .NET 3.5 CLR test here: https://laibalion.dyndns.org:5001/fbsharing/rHN9Ru5Y (don't worry about invalid certificate, I haven't installed a valid one on my NAS).

    Friday, January 18, 2013 8:49 AM
  • Have you tried to change the platform toolset for the class library project to Visual Studio 2008 (v90) as it should target .NET 3.5?

    Saturday, January 19, 2013 1:02 PM
  • Hi, that would mean that we will compile the C++/CLI code with vc9 compiler, which will cause several problems.

    First: we won't be able to use C++0x code.
    Second: we won't be able to link to our C++ backend, which will be compiled with v110. And mixing runtimes is a very bad thing.

    Saturday, January 19, 2013 2:08 PM
  • When you compile with /clr it will target the .NET framework associated with the toolset used. If you want to target a lower version of the runtime you need to use the corresponding toolset.

    If not, you will mix runtime versions. Isn't that the issue you see now? 

    Saturday, January 19, 2013 3:00 PM
  • Well that's definately how it was with previous visual studio versions(2008, 2010), but in VS2012 this has gotten a bit more flexible.

    vc11 can targer both 4.0 and 4.5. Those version are very similar, so perhaps thats why both are supported, where .NET 3.5 is very different (different CLR etc).

    So I guess it's safe to assume it is not possible to target .NET 3.5 with vc11, and that it's a bug that the compiler doesn't complain about it.

    • Marked as answer by Mike Feng Monday, February 4, 2013 5:51 AM
    • Unmarked as answer by Mike Feng Monday, February 4, 2013 5:52 AM
    Sunday, January 20, 2013 2:06 PM
  • Yepp... as it seems, you cannot compile a C++ .NET 3.5 project from VS2012 without VS2008 installed.

    Sunday, January 20, 2013 6:21 PM