Ivan Valadares
Ivan Valadares

Reputation: 949

Running different frameworks in the same solution?

I have a class library using .Net Framework 4.5, in the code I'm using HttpWebRequest of System.Net.

If I use in a console application using .Net Framework 4.5, it's ok.

If I use in a console application using .Net Core 2.2, it's ok but it's using System.net from .Net Core 2.2 and not from .Net Framework 4.5.

There's a bug/correction in .Net Core 2.2 HttpWebRequest and I want to use the .Net Framework 4.5 version but my application is in .Net Core 2.2.

Is this possible?

Upvotes: 0

Views: 585

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239430

Nope. It's best to think of the target framework for a class library as simply an interface. It's dictating a certain API footprint, but the actual framework code is not bundled into the class library.

The actual framework dependencies are satisfied by the end application that utilizes the class library. As long as there's an acceptable level of API compatibility, then you can add the reference, but when it comes time to compile, the target framework will be that of the application itself, not the class library.

If you absolutely need the .NET Framework version, then your only choice is to make your console application target .NET Framework as well, instead of .NET Core. You can still use the new project format; you just won't benefit from cross-platform or things like being able to deploy self-contained.

Upvotes: 3

Related Questions