简体   繁体   中英

How to get code library targetting .Net 4 to work with .Net 3.5 application

I'm building a new code library and would like to use .Net 4 as my target framework as all my new apps will use .net 4. My legacy web apps use .Net 3.5. I want to use this code library for all of my apps.

At this point, I see only 2 options

  1. Compile the dll for each framework I need, changing the target framework each time
  2. Create separate projects with differing target frameworks.

Is there any way around this so my code library is a single compile? Didn't know if there was something built into 4 to allow something like this.

Why not just build your libraries against .NET 3.5?

  • If they're trying to use .NET 4 features then obviously they won't work against your .NET 3.5 webapps anyway
  • If they're not, then using .NET 3.5 should be fine

There are some caveats around interop and mixed-mode assemblies, but for pure-C# assemblies it shouldn't be a problem.

It's possible to have different build configurations targeting different versions of the framework, but a bit of a pain - you'll need to mess with the project files manually. See the project files for MiscUtil as an example.

I don't see why you were happy with the .NET 2 / .NET 3.5 situation before - it's not very significantly different to that.

Of course, updating your webapps to run on .NET 4 would probably be the best solution, going forward.

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