有没有办法在 Visual Studio 中自动更新已安装的 NuGet 包? [英] Is there a way to automatically update an installed NuGet package in Visual Studio?

查看:106
本文介绍了有没有办法在 Visual Studio 中自动更新已安装的 NuGet 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我想知道是否有办法在包源中有新版本可用时自动更新已安装的 NuGet 包.

As the title says, I'd like to know if there is a way to automatically update an installed NuGet package as soon as a new version becomes available in the package source.

用例是一个将某些公司政策(代码分析、签名等)应用于我们的项目的包,一旦此包更新,我希望能够配置自动更新这个包.

The use case is a package that applies certain company policies (code analysis, signing, ...) to our projects, and as soon as this package is updated, I'd like to be able to configure an automatic update for this package.

我知道 NuGet 有一个包还原功能,它会在项目构建时自动下载丢失的包,但这会下载特定版本或具有匹配名称的最新包吗?

I do know that there is a package restore feature for NuGet which will automatically download the missing packages when the project is built, but does this download a specific version or the most recent package with a matching name?

推荐答案

NuGet 包还原功能特意仅适用于一个特定版本.同一个版本号不同的包,如果缺少版本号较低的包,将不会使用.

The NuGet package restore feature intentionally only works for one specific version. The same package with a different version number will not be used if the package with a lower version is missing.

示例 1

  • packages.config 引用 1.0.0.0
  • 包源包含 1.0.0.0 和 1.0.0.1
  • 1.0.0.0是会自动恢复的版本
  • packages.config references 1.0.0.0
  • package source contains 1.0.0.0 and 1.0.0.1
  • 1.0.0.0 is the version that will automatically be restored

示例 2

  • packages.config 引用 1.0.0.0
  • 包源仅包含 1.0.0.1
  • 不会执行自动恢复,项目不会构建

这种行为是有道理的,否则就无法控制您实际构建的内容.想象一下,在您构建将要发布的版本之前,有人用更新版本的包更新了包源...

This behaviour makes sense as otherwise there is no way to control what you are actually building. Imagine someone updates the package source with a newer version of a package just before you build a release that will get shipped...

这篇关于有没有办法在 Visual Studio 中自动更新已安装的 NuGet 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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