简体   繁体   English

Visual Studio:执行“还原NuGet包”时如何添加nuget包作为引用

[英]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 我已经使用packages.config中存在的“还原NuGet软件包”下载了所有packages.config

However, they do not appear in the References, so VS is not aware of them. 但是,它们没有出现在参考中,因此VS无法识别它们。

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. 这些引用将作为项目文件的一部分进行跟踪,并且通常作为NuGet软件包的初始安装的一部分进行添加。 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 . 为此,请在程序包管理器控制台中运行带有-reinstall标志的Update-Package命令

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. (可选)如果需要使用非最新版本,则可以添加-Version标志 ,只需使该版本号与您packages.config文件中存储的版本号匹配即可。

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. 我也有VS2017。但是,我没有遇到Nuget包的任何问题。

Anyway, try this: Right-click the References folder in the project, then click "Manage Nuget Packages" then click "Restore". 无论如何,请尝试以下操作:右键单击项目中的References文件夹,然后单击“ Manage Nuget Packages”,然后单击“ Restore”。

If that doesn't work, close VS, delete all files in bin, obj and packages folders and then repeat the steps above. 如果那不起作用,请关闭VS,删除bin,obj和packages文件夹中的所有文件,然后重复上述步骤。

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: 还要确保在“工具/选项/ Nuget程序包管理器”设置中选中“允许NuGet下载丢失的程序包”和“在构建过程中自动检查丢失的程序...”项,如下所示: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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