简体   繁体   中英

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. 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. 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. 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.

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.

I could manually update the .csproj files as well, for example by finding and replacing

<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. 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.

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?

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.
  • Batch replace the package version in the all package.config
  • Batch replace the package version and reference assembly version in all .csproj files via the third party tool, such as notepad++.

I wouldn't try updating packages manually, unless you're on .NET Core which treats NuGet packages as first class citizens.

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? Perhaps one of them is timing out.

Have you tried running Fiddler to see if there are extraneous network requests being made? Does the problem occur on all machines or just a specific one? Are they developer workstations or build servers?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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