nuget - 如何为不同的构建配置指定不同的 nuget 包版本?

标签 nuget csproj

我想为不同的项目配置指定不同的包版本。我知道这在我的 .csproj 文件中对于非 NuGet 依赖项(“裸”DLL)会是什么样子,但我也想尝试让它与 NuGet 包一起使用。

问题是 NuGet 依赖项是在 packages.config 中指定的,而不是在 .csproj 文件中,我可以在其中使用 MSBuild Condition属性。更糟糕的是,似乎没有关于 packages.config 及其支持的属性的任何文档。

这能做到吗?如何?

最佳答案

2019 PackageReference 即 使用 PackageReference 节点直接在项目文件中管理 NuGet 依赖项(而不是单独的 packages.config 文件)你能行的。

<ItemGroup>
<!-- ... -->
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'net452'" />
<!-- ... -->
</ItemGroup>

有关更多信息,您可以查看此 link .

Visual Studio 2017 版本 15.7 及更高版本支持 migrating a project from the packages.config management format to the PackageReference format .

关于nuget - 如何为不同的构建配置指定不同的 nuget 包版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35895601/

相关文章:

c# - 如何在VS中创建sdk样式的.net框架项目?

asp.net - 在 MSBuild 期间运行 powershell 脚本

msbuild - 使用 .NET Core csproj VS 2017 工具最小化引用

asp.net - Ajax 控制工具包、Visual Studio 2013、Nuget : AjaxControlToolkit. dll 丢失

c# - .csproj 文件中的 ProductVersion 设置由什么控制?

.net-core - 从 .NET Core 中的 C# 访问 `.csproj` 属性

continuous-integration - 如何配置 NuGet.exe 命令工具行查找包的位置

.net-core - 库是否应该明确针对 .NET Core 3?

.net-core - NU1100 : Unable to resolve 'System.Reflection.TypeExtensions (>= 4.5.1)' for '.NETStandard,Version=v1.3'

c# - 如何使用 NuGet v3 API 下载和解压缩包