- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 .NET 较旧的 NuGet packages.config
系统下,I could constrain the possible versions of a package在使用 allowedVersions
更新软件包时考虑Package 元素上的属性
<package id="Newtonsoft.Json" version="10.0.3" allowedVersions="[10.0.3]" />
当 update-package
在 Visual Studio 中针对包含上述内容的项目运行,Newtonsoft.Json
不会发生更新,因为我已使用 allowedVersions
属性固定到 10.0.3。
我如何在 PackageReference
下实现这一点? ?正在申请 semver Version 属性的语法只影响版本恢复 - 它不限制更新。因此,如果我指定以下 PackageReference
并运行 update-package
,例如,如果 11.0.1 在我的 NuGet 存储库中,我将升级到 11.0.1。
<PackageReference Include="Newtonsoft.Json" Version="[10.0.3]" />
我们依靠命令行工具来更新包,因为我们既有快速移动的内部包(每天更新多次),也有更稳定的低移动包(例如:ASP.NET)。在大型代码库上,手动更新 .csproj
文件中的每个依赖项对我们来说根本不可扩展(并且容易出错)。在 packages.config
下,我们可以“固定”我们不想升级的第三方包,也可以更新到最新的快速移动依赖项。
最佳答案
来自 this answer :
At the moment, this is not possible. See this GitHub issue for tracking.
The cli commands for adding references however support updating single packages in a project by re-running
dotnet add package The.Package.Id
.
来自 GitHub Issue 4358 :
There is no
PackageReference
replacement forupdate
yet, the command to modify references is only indotnet
.
您可能想参与开放功能请求 GitHub issue 4103关于这个(4358 作为重复关闭)。 Microsoft 并未将此功能放在高优先级(它最初于 2016 年 10 月开放)。
可以通过删除和添加引用来“更新”依赖项。根据this post ,使用命令明确指定版本将安装准确版本,而不是最新版本。我还确认您可以使用以下命令添加版本限制:
dotnet remove NewCsproj.csproj package Newtonsoft.Json
dotnet add NewCsproj.csproj package Newtonsoft.Json -v [10.0.3]
您可以使用这些命令做什么:
packages.config
)。.sln
文件来处理其中的每个项目。使用 MSBuild 从通用 MSBuild 文件“导入”依赖项,您可以在一个地方更新版本。
您可以定义自己的<IncludeDependencies>
元素以包含每个项目的特定依赖项。
SomeProject.csproj
<Project Sdk="Microsoft.NET.Sdk">
<IncludeDependencies>Newtonsoft.Json;FastMoving</IncludeDependencies>
<Import Project="..\..\..\Dependencies.proj" />
...
</Project>
Dependencies.proj
<Project>
<ItemGroup>
<PackageReference Condition="$(IncludeDependencies.Contains('Newtonsoft.Json'))" Include="Newtonsoft.Json" Version="[10.0.3]" />
<PackageReference Condition="$(IncludeDependencies.Contains('FastMoving'))" Include="FastMoving" Version="3.332.0" />
</ItemGroup>
</Project>
关于c# - update-package 运行时约束 PackageReference 升级版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49398602/
Nuget.Config 中是否有任何方法可以将包管理选项默认为“PackageReference”?我将假设没有,因为我没有看到它 here但我想我会问。 我希望在某个存储库的所有开发人员机器上默认
我正在尝试使用 Directory.Builds.props/Directory.Build.targets 文件来集中我们的一些项目配置。不幸的是,我们混合了新旧(sdk 样式)项目格式。由于新格式
在我的 VS 2017 项目中,我引用了 docfx.console 包,我希望它仅在满足特定条件时使用。但是该包被用于所有构建。 这是我项目的一部分。我希望在配置为 Installer/AnyCPU
背景 我正在处理一个包含多个大型解决方案的大型项目。总而言之,我们有超过 400 个 C# 项目。过去我们使用 Nuget 和 packages.config我们的依赖文件。现在我们要将所有项目迁移到
我正在清理一个项目,该项目已经经历了大部分开发周期并且几乎准备好投入生产。我想删除 csproj 中任何不需要的 PackageReference,但似乎找不到任何方法来检测它们,除了可能单独删除每个
我的 NetStandard 项目中有以下内容 当我将其更改为使用通配符(而不是 1.0.1)时,我在依赖项切换上得到一个感叹号,然后是 NuGet 切换,当然还有包本身。 当我 checkin
我们有一堆快速移动的内部 nuget 包。 我们希望这些软件包的使用者始终使用最新版本。目前,我们通过在构建之前在命令行上运行 nuget update 在 CI 系统上执行此操作。 但是我们现在正在
我正在尝试通过 Jenkins Pipeline 运行以下命令 bat 'nuget restore mySolution.sln -MSBuildPath "C:\\Program Files (x
让我们考虑一下这样的场景:我们有两个 .NET Standard 项目,我们想要为其公开并创建 NuGet 包: 图书馆解决方案 类库1 (CL1) ∟类库2(CL2) 值得一提的是,CL1 有一个对
将 WindowsRuntime 添加到 WinForms 项目后,构建项目失败,并出现错误“必须使用 PackageReference”。构建日志更加精确: C:[...]\Visual Studi
我有许多针对 .net 4.6.1 的项目的解决方案。在我们的 MS 构建服务器上,它构建得很好。我最近添加了一个针对 .NET Standard 1.3 的项目。这不会在构建服务器上构建。它在本地使
我正在使用 Microsoft Visual Studio Community 2022(64 位)- 预览版 17.3.0 预览版 1.1。 错误 Severity Code Descr
发布 Nuget 包时指定 PackageReference 的最佳做法是什么? 根据 https://learn.microsoft.com/en-us/nuget/consume-packages
重现步骤: 打开Visual Studio 2017,新建类库项目,.NET 4.6.1 . 添加对 Newtonsoft.Json 的引用使用 Nuget 包管理器。 使用 VS2017 成功构建项
我创建了一个 Directory.Build.props通过右键单击“解决方案资源管理器”上的“解决方案”,创建一个 XML 文件并为其命名。然后我输入此 XML 并尝试构建,但遇到了错误:
我正在将旧式 MsBuild csproj 项目迁移为使用 PackageReference 格式,但遇到了传递依赖项问题。 考虑以下因素项目 A 引用 NuGet 包 B 和 C,每个包都包含一个使
我有一个带有一些 NuGet 依赖项的项目,使用 PackageReference: 我不希望依赖直接安装在bin\${buildConfiguration}\${framew
在我的项目中,我像这样使用 PackageReference 引用了一些包: 但是,如果我运行 pack 命令,它不会包含它们,除非我手动将它们添加到 .nuspec 文件中。 我想将我的 C# 项目
在 .NET 较旧的 NuGet packages.config 系统下,I could constrain the possible versions of a package在使用 allowed
ProjectA引用文献 ProjectB ProjectB引用文献 ProjectC ProjectA有PackageReference在 .csproj 鉴于以上,可以直接引用ProjectC输入
我是一名优秀的程序员,十分优秀!