Mindaugas Bernatavičius
Mindaugas Bernatavičius

Reputation: 3909

Visual Studio: how to add nuget packages as references when doing "Restore NuGet packages"

I have downloaded all the packages using "Restore NuGet packages" that existed in packages.config

However, they do not appear in the References, so VS is not aware of them.

Is there a way to add them automatically to the reference list? Possibly in 1 step?

enter image description here

Upvotes: 3

Views: 2594

Answers (2)

corix010
corix010

Reputation: 571

I too have VS 2017. However, I haven't encountered any problem with Nuget packages.

Anyway, try this: Right-click the References folder in the project, then click "Manage Nuget Packages" then click "Restore".

If that doesn't work, close VS, delete all files in bin, obj and packages folders and then repeat the steps above.

Also make sure the items "Allow NuGet to download missing packages" and "Automatically check for missing packages during build..." are checkekd in Tools/Options/Nuget Package Manager setting as follows: enter image description here

Upvotes: 0

Reddog
Reddog

Reputation: 15579

The references are tracked as part of the project files and are usually added as part of a NuGet package's initial installation. Restoring the packages will just download them.

This means it sounds like you need to reinstall those specific packages whose references are missing.

To do this, run the Update-Package command in the Package Manager Console with the -reinstall flag on it.

Update-Package <package_name> -ProjectName MyProject -reinstall

Optionally, you can add the -Version flag if you need to stick with a version that's not the latest, just make this version number match that stored in your packages.config file.

Or alternatively, to reinstall all packages for a given project:

Update-Package -Reinstall -ProjectName <project_name>

Upvotes: 3

Related Questions