简体   繁体   English

如何在不使用Nuget UI或命令行工具的情况下手动更新Nuget软件包

[英]How to manually update a Nuget package without using the Nuget UI or command line tool

I'm working on a large solution that consists of over 250 projects. 我正在研究一个包含250多个项目的大型解决方案。 Updating a common Nuget package that's used in all those projects takes between 2 and 3 hours when using either the Visual Studio Nuget UI or the Nuget command line tool. 使用Visual Studio Nuget UI或Nuget命令行工具时,更新在所有这些项目中使用的通用Nuget程序包需要2到3个小时。 I'm looking for a way to do this more quickly by updating the files manually. 我正在寻找一种通过手动更新文件来更快地执行此操作的方法。

My first thought was that I'd only need to update the package version number in each project's *.config file. 我首先想到的是,我只需要更新每个项目的*.config文件中的软件包版本号即可。 For example, find and replace 例如,查找并替换

<package id="ThisPackage" version="0.0.0.1" targetFramework="net452" />

with

<package id="ThisPackage" version="0.0.0.2" targetFramework="net452" />

This seems to be what actually happens when you perform an update via the VS Nuget UI so I thought doing this and then rebuilding the solution would take care of everything, a bit like manually editing the dependencies in package.json and then running npm install in Node. 这似乎是通过VS Nuget UI执行更新时实际上发生的事情,因此我认为这样做然后重新构建解决方案将解决所有问题,有点像手动编辑package.json的依赖项,然后在其中运行npm install节点。

This doesn't work however; 但是,这不起作用。 the references in the .csproj files don't get updated on build the way you do when the config files are updated by Nuget. .csproj文件中的引用在构建时不会像Nuget更新配置文件时那样进行更新。

I could manually update the .csproj files as well, for example by finding and replacing 我也可以手动更新.csproj文件,例如通过查找和替换

<HintPath>..\..\packages\ThisPackage.0.0.0.1\

with

<HintPath>..\..\packages\ThisPackage.0.0.0.2\

But presumably I also need to update the referenced assembly versions and I'm not sure how to work out what they should be for a given version of a Nuget package. 但是大概我也需要更新引用的程序集版本,而且我不确定如何确定给定版本的Nuget程序包应该是什么。 Plus at this point it's getting a bit fiddly and error-prone albeit about half an hour of work instead of 3 hours of dead time. 另外,这虽然有点麻烦,但容易出错,尽管工作大约需要半小时,而不是3个小时的停滞时间。

Has anyone found a way to update a Nuget package across a large number of projects in a solution that doesn't take multiple hours? 有没有人找到一种无需花费多个小时的解决方案即可在大量项目中更新Nuget软件包的方法?

The package update time is consist of downloading package and uninstalling/installing package. 软件包更新时间包括下载软件包和卸载/安装软件包。 The downloading action will execute only once when first time download it, so the uninstalling/installing action will occupy almost all update time. 首次下载时,该下载操作仅执行一次,因此,卸载/安装操作几乎占据了所有更新时间。 So you can accept the Kiliman`s advice to check your machine performance at first. 因此,您可以首先接受乞力曼的建议来检查机器性能。

If you want to update all those packages manually according to your steps. 如果要根据您的步骤手动更新所有这些软件包。 You can follow below steps to reduce the update time: 您可以按照以下步骤减少更新时间:

  • Downloading the update package and place it to your local package repository. 下载更新程序包并将其放置到本地程序包存储库中。
  • Unzip the package, then find the referenced assembly versions. 解压缩软件包,然后找到引用的程序集版本。 Or you can use the NuGet Package Explorer tool to get the referenced assembly versions. 或者,您可以使用NuGet包资源管理器工具来获取引用的程序集版本。
  • Batch replace the package version in the all package.config 批量替换所有package.config中的软件包版本
  • Batch replace the package version and reference assembly version in all .csproj files via the third party tool, such as notepad++. 通过第三方工具(例如notepad ++)批量替换所有.csproj文件中的软件包版本和参考程序集版本。

I wouldn't try updating packages manually, unless you're on .NET Core which treats NuGet packages as first class citizens. 我不会尝试手动更新软件包,除非您使用的是.NET Core,它将NuGet软件包视为头等公民。

Right now, there is too much going on with downloading packages, updating project references, etc. that it would be far too error-prone to try to do it yourself. 现在,下载软件包,更新项目引用等方面的工作太多了,以至于无法自己尝试进行操作就很容易出错。

Now perhaps the real question is why is it taking so long to update packages. 现在也许真正的问题是为什么更新包需要这么长时间。 Have you added other NuGet repositories? 您是否添加了其他NuGet存储库? Perhaps one of them is timing out. 也许其中之一正在超时。

Have you tried running Fiddler to see if there are extraneous network requests being made? 您是否尝试过运行Fiddler以查看是否发出了无关的网络请求? Does the problem occur on all machines or just a specific one? 问题是在所有机器上还是仅在特定机器上发生? Are they developer workstations or build servers? 他们是开发人员工作站还是构建服务器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM