Doro
Doro

Reputation: 785

Restoring NuGet packages to the latest version

In the project I've been using some custom NuGet sources. Apparently some of them are no longer available but I do have the newer (and only newer) versions of the packages on the other (still working) server. Is there a way to restore the packages directly to the newest versions without manually replacing all the references in the .csproj and packages.config files?

I've tried running Updade-Package -Reinstall but I only get the following error message:

Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations.

Upvotes: 2

Views: 1859

Answers (1)

Jérôme MEVEL
Jérôme MEVEL

Reputation: 7804

If some packages you use (and still want to use) are no longer available, I suggest you to make a backup of them.

Find the Nuget cache on your server. On Windows this is located at

%userprofile%.nuget\packages

Spot the packages (and version) you want to backup and copy the .nupkg files in their respective folders.

Then you have two choices:

  1. Create a private Nuget feed
  2. Create a local Nuget feed on your development machine

The 1st option has the advantage to be a single source that can be used on any machine you want (development machine, build server...etc) but you will have more set-up, especially for the authentication/authorization (because it's a private feed)

For the 2nd option: Simply create a C:/Nuget folder and put any .nupkg you want. Then in Visual Studio go to:

Tools -> Nuget Package Manager -> Package Manager Settings -> Package Sources

Click on the green + button to add a new source, simply give it the name Local and browse to your C:/Nuget to set the source.

From now on when you want to restore your Nuget packages, Visual Studio will first look into the nuget.org feed and if it doesn't find the referenced packages, will then look into your Local feed and cache the installed package to the %userprofile%.nuget\packages of your machine.

I hope that answer to your question, I was not quite sure about what you asked and your knowledge about Nuget.

UPDATE:

I think I understand your question better now.

First of all, I think your misunderstand the Update-Package -Reinstall command. It will reinstall the packages with the SAME version as already referenced but simply reinstalling them. It's a useful command for example when you change the target framework of your project. Then you can reinstall the same versions of the packages and they will retarget this .NET Framework version.

So if a nuget restore isn't working then Update-Package -Reinstall will obviously fail too.

With Nuget, when something isn't working, you shouldn't insist but instead, find the tweak that will make it working again. I can't count how many times I went to the different caches to delete some cached packages.

I think you should try to use nuget restore and see what packages are causing issues, then uninstall these packages (this will just remove the reference from the .csproj and packages.config if they aren't installed in the project yet), then you can finally install the newest version of these packages.

Upvotes: 2

Related Questions