简体   繁体   English

如何为特定版本的 .NET 创建具有特定依赖性的 nuget package

[英]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.

相关问题 强制 Nuget 包使用特定版本的子依赖项? - Force Nuget package to use specific version of sub dependency? 如何卸载NuGet软件包的特定版本? - How to uninstall specific version of a NuGet package? 如何解决nuget包中依赖版本的冲突? - How to resolve a conflict in dependency version in a nuget package? 如何安装特定版本的nuget? - How to install a specific version of nuget? 使用NuGet将依赖关系限制为特定的.NET版本 - Restrict Dependencies to specific .NET version using NuGet 如何在解决方案中使用特定版本的nuget dll - How to use specific version of nuget dll in solution Nuget 无法安装 package "RazorGenerator.Mvc" 与特定版本 2.3.12 - Nuget Failed to install package "RazorGenerator.Mvc" with specific version 2.3.12 有没有一种方法可以在构建时自动安装特定版本的Nuget软件包? - Is there a way to automatically install a specific version of a Nuget Package at build time? 在引用多目标 class 库时,如何让 NuGet 了解 package 的特定版本? - How do I make NuGet aware of a specific version of a package while referencing a multi-targeted class library? 如何测试NuGet软件包是否与较低版本的依赖项一起工作? - How to test if a NuGet package works with a lower version of its dependency?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM