0

I'm creating a class library that's intended to be consumed by projects running anything from .NET 4.5.0 up through .NET Core. Currently all of the actual meat of the library is working just fine, but I can't figure out how to grab values from the web.config of the consuming project without encountering issues. The System.Configuration.ConfigurationManager nuget class doesn't support anything lower than .net 4.6 because .NET 4.5 has it built-in. As such, I want to only require the installation of the nuget package if the target is 4.6+.

Is that possible?

Alex Kibler
  • 4,674
  • 9
  • 44
  • 74
  • You can think about creating your nuget package as [.NET Standard](https://learn.microsoft.com/en-us/dotnet/standard/net-standard) package – Pavel Anikhouski Sep 24 '19 at 18:33
  • Possible duplicate of [How do you multi-target a .NET Core class library with csproj?](https://stackoverflow.com/questions/42747977/how-do-you-multi-target-a-net-core-class-library-with-csproj) – Joakim Skoog Sep 25 '19 at 10:17

1 Answers1

0

That's entirely possible, you can do it with a conditional ItemGroup in your project file. Example:

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
    <PackageReference Include="System.Configuration.ConfigurationManager" 
    Version="4.4.1" />
</ItemGroup>

Note that I'm assuming that you're using the new .csproj format and Package references

Joakim Skoog
  • 766
  • 10
  • 23