user3012708
user3012708

Reputation: 946

How can I create a NuGet package that uses both .NET Framework and .NET Core configuration?

I'm trying to allow the constructor to accept IConfiguration for .Net, and a reference to ConfigurationManager or similar for .Net Framework/Standard.


I am trying to create a conditional constructor for a class that needs to know which runtime it's running against - namely whether it's in a Framework, or .NET solution.

The solution that this class resides in is written against .Net Standard, but will be consumed by .Net Framework 4.8, .Net Standard 2.0 and .Net 6/7 applications/packages.

Initially I thought conditional compilation would be the answer, with this as an example:

#if NETSTANDARD || NETFRAMEWORK
    //do stuff
#elif NET
    //do different stuff
#endif

However, this is not about compilation time - it will always be compiled to .Net Standard.

Is there a way to figure out what runtime is being used, and conditionally present constructors that way?

I could just include all constructors and include comments on what to use when, but i feel like that will be ignored, and if i could force the correct usage, it would be simpler.

I'm trying to allow the constructor to accept IConfiguration for .Net, and a reference to ConfigurationManager or similar for .Net Framework/Standard.

Worse - i'm trying to do this without different compilations as this is the only real area where the package i'm updating differs in functionality between .Net and Framework.

Upvotes: 0

Views: 201

Answers (0)

Related Questions