如何为不同的构建配置指定不同的nuget软件包版本? [英] How to specify different nuget package versions for different build configurations?

查看:83
本文介绍了如何为不同的构建配置指定不同的nuget软件包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to specify different package versions for different project configurations. I know what this would look like in my .csproj file for non-NuGet dependencies ("bare" DLLs), but I'd like to try and get this working with NuGet packages too.

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

The problem is that NuGet dependencies are specified in packages.config and not in the .csproj file, where I could use the MSBuild Condition attribute. This is compounded by the fact that there does not appear to be any documentation for packages.config and the attributes it supports.

可以这样做吗?

推荐答案

2019 中的PackageReference,它使用PackageReference节点来管理NuGet依赖项您可以直接在项目文件中(而不是单独的packages.config文件)进行操作。

In 2019 PackageReference which is using the PackageReference node to manage NuGet dependencies directly within project files (as opposed to a separate packages.config file) you can do it.

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

有关更多信息,请检查链接

For more information you can check this link.

Visual Studio 2017 15.7版和更高版本支持将项目从packages.config管理格式迁移到PackageReference格式

Visual Studio 2017 Version 15.7 and later supports migrating a project from the packages.config management format to the PackageReference format.

这篇关于如何为不同的构建配置指定不同的nuget软件包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆