简体   繁体   中英

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?

在此处输入图片说明

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>

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: 在此处输入图片说明

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