简体   繁体   English

NuGet 安装包时添加引用错误

[英]NuGet add reference error while installing packages

I am not able to install any package by Nuget.我无法通过 Nuget 安装任何软件包。 For example when I want install entity framework I receive following error:例如,当我想安装实体框架时,我收到以下错误:

install-package EntityFramework
Successfully installed 'EntityFramework 4.2.0.0'.
Successfully uninstalled 'EntityFramework 4.2.0.0'.
Install failed. Rolling back...
Install-Package : Failed to add reference to 'EntityFramework'.
At line:1 char:16
+ install-package <<<<  EntityFramework
   + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
   +FullyQualifiedErrorId:NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

I receive same error while installing every package from console or gui.从控制台或 gui 安装每个软件包时,我收到相同的错误。 Reinstalling nuget, disabling other extentions and running VS as admin did not help me.重新安装 nuget,禁用其他扩展并以管理员身份运行 VS 对我没有帮助。

Regards问候

I had this problem too, the fix that worked for me was:我也有这个问题,对我有用的解决方法是:

  1. Delete all the folders inside of the packages folder.删除packages文件夹内的所有文件夹。
  2. Update all packages in Nuget Package Manager.在 Nuget 包管理器中更新所有包。

Suffer the same.受同样的苦。 In the end it occurs that in最后它发生在

Tools -> Options -> Nuget Package Manager -> Package Sources 

nuget.org was unchecked. nuget.org 未选中。 Checking it solve the problem.检查它可以解决问题。

Here is what solved it for me: VS2012 with EF6EF6 VS2012:这里是解决了这个问题对我来说

I found my answer here: http://richardschneider.net/blog/wordpress/?p=21我在这里找到了答案: http : //richardschneider.net/blog/wordpress/?p=21

From the VS command prompt, run the following command:从 VS 命令提示符运行以下命令:

regsvr32 "C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VsLangproj.olb"

After that, go to Package manager console and run the following:之后,转到包管理器控制台并运行以下命令:

Install-Package EntityFramework -Version 6.1.3

I ran into this issue as well.我也遇到了这个问题。 Unfortunately, the only solution that worked for me was completely uninstalling Visual Studio, deleting any folders left over after the uninstall, rebooting computer, and then re-installing Visual Studio.不幸的是,唯一对我有用的解决方案是完全卸载 Visual Studio,删除卸载后剩余的所有文件夹,重新启动计算机,然后重新安装 Visual Studio。

Visual Studio 'repair' did not work for me. Visual Studio“修复”对我不起作用。 Only complete re-install.只能完全重新安装。

我也有这个问题我所做的是在包管理器控制台中键入Uninstall-Package EntityFramework -force ,然后删除包文件夹中的 EntityFramework 文件夹,然后再次Install-Package EntityFrameworkInstall-Package EntityFramework

通过清除包缓存问题解决了:

Tools->package Manager->Package Manager Settings-> Clear Package Cache

After updating my Visual Studio 2015 nuget stopped working.更新我的 Visual Studio 2015 nuget 后停止工作。

After reading the posted solutions I founded that's a know bug, see http://blog.nuget.org/20150226/nuget-3.0-beta2.html阅读我发现的已发布解决方案后,这是一个已知错误,请参阅http://blog.nuget.org/20150226/nuget-3.0-beta2.html

From Visual Studio I unistalled nuget extension, closed visual studio , downloaded and installed latest nuget version from https://dist.nuget.org/index.html我从 Visual Studio 卸载了 nuget 扩展,关闭了 Visual Studio,从https://dist.nuget.org/index.html下载并安装了最新的 nuget 版本

It worked有效

I ran into the same problem.我遇到了同样的问题。 I did the following:我做了以下事情:

update-package jQuery.

Install-Package Twitter.Bootstrap -Version 3.0.0

It worked , probably because the Bootstrap -version 3.0.0 work with the JQuery most recent version.它有效,可能是因为Bootstrap -version 3.0.0JQuery 的最新版本一起使用。

对我来说,问题已通过git clean -dfx

Running this command from an elevated prompt resolved my issue:从提升的提示符运行此命令解决了我的问题:

regsvr32 "C:\\Program Files (x86)\\Common Files\\microsoft shared\\MSEnv\\VsLangproj.olb" regsvr32 "C:\\Program Files (x86)\\Common Files\\microsoft shared\\MSEnv\\VsLangproj.olb"

Source: https://docs.nuget.org/Release-Notes/Known-Issues来源: https : //docs.nuget.org/Release-Notes/Known-Issues

Had nearly the same problem on my Windows 10 machine and could't figure out why no references worked in Visual Studio 2015 after running "Get Latest Version" in TFS and why I could not restore NuGet packages.在我的 Windows 10 机器上遇到了几乎相同的问题,并且无法弄清楚为什么在 TFS 中运行“获取最新版本”后在 Visual Studio 2015 中没有引用工作,以及为什么我无法恢复 NuGet 包。 For some reason NuGet added two packages folders to the computer and I had only deleted the package folder in the project:出于某种原因,NuGet 向计算机添加了两个包文件夹,而我只删除了项目中的包文件夹:

Locations:地点:

C:\\Users\\YourUser\\Documents\\Visual Studio 2015\\Projects\\YourProject\\packages C:\\Users\\YourUser.nuget\\packages C:\\Users\\YourUser\\Documents\\Visual Studio 2015\\Projects\\YourProject\\packages C:\\Users\\YourUser.nuget\\packages

When both of the packages folders were removed I could restore NuGet packages and everything worked again.当两个包文件夹都被删除后,我可以恢复 NuGet 包,一切又恢复正常了。

When I went to Visual Studio 2015 Update 3, it broke for me, I tried many of the steps, in other answers to clear package folders / caches / etc.当我转到 Visual Studio 2015 更新 3 时,它对我来说崩溃了,我尝试了许多步骤,在其他答案中清除包文件夹/缓存/等。

In the end I got it working via:最后,我通过以下方式使其工作:

  • Full uninstall.完全卸载。
  • Went looking for all files/locations of visual studio (AppData/Documents/etc).去寻找 Visual Studio (AppData/Documents/etc) 的所有文件/位置。
  • New re-install, it still didn't work (I had missed files in other locations).重新安装,它仍然不起作用(我错过了其他位置的文件)。
  • Ran devenv commands : like /resetuserdata and /resetsettings运行devenv命令:如/resetuserdata/resetsettings
  • Ran a repair action.进行了修复操作。

So just note doing a full uninstall won't clear out all your settings/cache data.因此,请注意完全卸载不会清除您的所有设置/缓存数据。

The problem occurred in my entity framework version.问题出现在我的实体框架版本中。 I was using an older version of entity framework, After deleting older version of EF and re installing it with the latest version available helped me solving this issue.我使用的是旧版本的实体框架,删除旧版本的 EF 并使用可用的最新版本重新安装后,帮助我解决了这个问题。

I deleted the project, created fresh one, first added entity framework reference.我删除了项目,创建了一个新项目,首先添加了实体框架引用。 it worked.. moved necessary code back into the project它有效..将必要的代码移回项目中

In my case, deleting all occurrences of 'EntityFramework...' files in the Bin folder (open the folder in Windows Explorer) worked form me.就我而言,删除 Bin 文件夹中所有出现的“EntityFramework...”文件(在 Windows 资源管理器中打开该文件夹)对我有用。 I didn't have the packages folder in my project.我的项目中没有包文件夹。 The 'EntityFramework...' files were added by different action. 'EntityFramework...' 文件是由不同的操作添加的。

NOTE: You may need to rebuild project to remove error(s).注意:您可能需要重建项目以消除错误。

I also ran into this case when installing the AttributeRouting package.我在安装 AttributeRouting 包时也遇到了这种情况。 After googling a while, i tried the following steps and it works for me:谷歌搜索一段时间后,我尝试了以下步骤,它对我有用:

  1. Tools > Extensions and Updates: uninstall NuGet Package Manager and reinstall it.工具 > 扩展和更新:卸载 NuGet 包管理器并重新安装。 Restart the Visual Studio.重新启动 Visual Studio。

  2. Tools > Options > Package Manager > Package Sources: make sure to check for the nuget.org source.工具 > 选项 > 包管理器 > 包源:确保检查 nuget.org 源。

Hope this help.希望这有帮助。

In my case, specifying the desidered version has solved the problem.就我而言,指定所需的版本已经解决了问题。 That's probably because different projects in the same solution reference different version of the same Package.这可能是因为同一解决方案中的不同项目引用了同一包的不同版本。 In that case, Nuget doesn't know the desidered version, hence the exception.在这种情况下,Nuget 不知道所需的版本,因此是例外。

Just use this syntax:只需使用以下语法:

Install-Package XXXX -Version A.B.C.D

I had this problem in Visual Studio 2017 in Windows 10.我在 Windows 10 的 Visual Studio 2017 中遇到了这个问题。

I had an existing project, and I updated the .Net Framework from 4.6.2 to 4.7.2, and the Entity Framework from 6.1.3 to 6.2.0.我有一个现有项目,我将 .Net Framework 从 4.6.2 更新到 4.7.2,将实体框架从 6.1.3 更新到 6.2.0。 I rebuilt and deployed the application, but it failed to connect to my database because the reference to EntityFramework.SqlServer was broken.我重建并部署了该应用程序,但它无法连接到我的数据库,因为对 EntityFramework.SqlServer 的引用已损坏。

I used the Package Manager UI to remove the Entity Framework from both projects in my solution.我使用包管理器 UI 从我的解决方案中的两个项目中删除实体框架。 I attempted to re-add the Entity Framework, but it failed every time.我试图重新添加实体框架,但每次都失败了。 I had to remove the Entity Framework from both projects and save the solution to source control (TFS) , and then add the Entity Framework back in.我必须从两个项目中删除实体框架并将解决方案保存到源代码管理 (TFS) ,然后重新添加实体框架。

This successfully added the Entity Framework and the EntityFramework.SqlServer reference.这成功地添加了实体框架和 EntityFramework.SqlServer 引用。

Add new Source with following path and Tick it.使用以下路径添加新源并勾选它。 https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/ https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/

工具 -> NuGet 包管理器 -> 包管理器设置 -> 转到包源并删除产生问题的源。

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

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