hardywang
hardywang

Reputation: 5162

Restore nuget packages defined in .nuget folder

There are some nuget packages (e.g. OpenCover or ReportGenerator) installed without changing packages.config in any of the project, but there is a [Solution Dir]\.nuget\packages.config created with the package reference information.

When VS builds the solution, the packages defined in that file are not downloaded at all (even I have auto restore nuget enabled).

How can I restore them automatically?

Upvotes: 2

Views: 734

Answers (1)

Matt Ward
Matt Ward

Reputation: 47937

The MSBuild based package restore, that uses NuGet.targets, which is enabled in Visual Studio by selecting Enable NuGet Package Restore, does not seem to support restoring solution level packages, which are those that are defined in the [SolutionDir]\.nuget\packages.config file.

Looking at the NuGet.targets file on build it restores the packages for the project using the project's packages.config file but does not use the solution's packages.config file.

So your options are:

  1. Stop using the MSBuild based package restore. Visual Studio, with recent versions of NuGet, will automatically restore all packages, including all solution level packages, when you build.
  2. Run NuGet.exe restore YourSolution.sln from the command line, or PowerShell console, or as a pre-build step, to restore all packages. NuGet.exe can be used to restore all packages on a build server if you are using one.

The MSBuild based package restore has been deprecated by the NuGet team so I would use option 1) if this is possible.

Upvotes: 2

Related Questions