简体   繁体   中英

C# .Net framework versioning

What can be the issues if I build a solution where all the projets are under targetFrameworkVersion=2.0 but one with targetFrameworkVersion=3.5 and

  1. None of the 3.5 features are used
  2. Some of the 3.5 features are used but the classes calling the 3.5 code are never instanciated
  3. Some of the 3.5 features are used in some classes, the classes are instanciated but the code in 3.5 never called
  4. the 3.5 code is called

It depends on what you mean by "features". There are compile-time features like the var keyword and lambda expressions and there are run-time features like LINQ or WCF that require libraries in the .NET 3.x runtime.

I assume you're using Visual Studio 2008, which will handle all the compile-time features. If all you're using is the compile-time features, then everything will work fine in all cases. I do this rather often on my current project.

If you're using run-time features then I believe this is how it will shake out:

  1. Things will just work.
  2. I think this will just work also.
  3. It depends on when static functions are JITted and if you have any 3.5 library referencing code in static functions.
  4. Probably MissingMethodException when a function containing a 3.5 library feature is called.

Rather than worry about all of this, if you're planning on using run-time features, I would simply add a key to the App.config that the 3.5 runtime is required and it'll check on startup and bomb if it isn't present. Then you don't need to figure out all these permutations and your application will be more stable.

First of all, you need to be aware that what you are targeting is actually .NET 2.0 SP1 .

How are your projects related? Do you have projects that are built under .NET 2.0 which reference the .NET 3.5 project (or vice versa)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM