[英]How to create a nuget package with specific dependency for a specific version of .NET
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.我正在创建一个 class 库,该库旨在供运行从 .NET 4.5.0 到 .NET 核心的任何项目使用。 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.
目前,该库的所有实际内容都运行良好,但我不知道如何从消费项目的 web.config 中获取值而不会遇到问题。 The System.Configuration.ConfigurationManager nuget class doesn't support anything lower than .net 4.6 because .NET 4.5 has it built-in.
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+.
因此,如果目标是 4.6+,我只想安装 nuget package。
Is that possible?那可能吗?
That's entirely possible, you can do it with a conditional ItemGroup in your project file.这完全有可能,您可以在项目文件中使用条件ItemGroup来做到这一点。 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请注意,我假设您使用的是新的
.csproj
格式和Package 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.