简体   繁体   English

NuGet有包丢失的问题,如何恢复?

[英]NuGet has problems with missing packages, how to restore?

When I try to compile my program I get the following error:当我尝试编译我的程序时,出现以下错误:

This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.    

Now when I right click on the solution and press现在,当我右键单击解决方案并按

All packages are already installed and there is nothing to restore.

I tried manually reinstalling every package which didn't solve the problem, I tried reinstalling NuGet but that didn't help either and I even tried reinstalling visual studio.我尝试手动重新安装每个没有解决问题的包,我尝试重新安装 NuGet 但这也没有帮助,我什至尝试重新安装 Visual Studio。

I also tried moving the package folder from the tfs folder to overwrite my package folder but that didn't solve anything.我还尝试从 tfs 文件夹中移动包文件夹以覆盖我的包文件夹,但这并没有解决任何问题。 I also tried redownloading them with this package missing, that didn' t solve the problem either.我还尝试在缺少此软件包的情况下重新下载它们,这也没有解决问题。

Anybody know how to restore the nuget packages?有人知道如何恢复nuget包吗?

Use Package Manager Console in Visual Studio to run this command.使用 Visual Studio 中的Package Manager Console运行此命令。

1.This will restore all packages from solution 1.这将从解决方案中恢复所有包

nuget restore YourSolution.sln

2.If you want to reinstall the packages to the same versions as were previously installed 2.如果要将软件包重新安装到与以前安装的版本相同的版本

Update-Package -reinstall

Honestly, whoever developed the NuGet command for VS needs to go back to the drawing board.老实说,无论谁为 VS 开发了 NuGet 命令,都需要回到绘图板。 They totaly missed the fact that sometimes these DLL(s) and/or files get corrupt or deleted.他们完全忽略了有时这些 DLL 和/或文件被损坏或删除的事实。 a "NuGet Get-Packages -Force" option would really save their bacon. “NuGet Get-Packages -Force”选项真的可以节省他们的培根。 The only GAP I see is that VS and the Package console does not allow you to invoke a forced download from NuGet.我看到的唯一差距是 VS 和 Package 控制台不允许您从 NuGet 调用强制下载。 Even clearing the cache via VS is useless.即使通过 VS 清除缓存也没有用。

I ran into this issue when I tried to build my project on a computer where the packages-folder did not already exist in the solution root.当我尝试在解决方案根目录中不存在包文件夹的计算机上构建我的项目时遇到了这个问题。

When the project file was initially created, it seems VS2019 added the following into the project file:最初创建项目文件时,VS2019似乎在项目文件中添加了以下内容:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>

From what I understand those settings are deprecated nowadays, no idea why VS inserted it in the first place.据我了解,这些设置现在已被弃用,不知道为什么 VS 首先插入它。

Anyway, after removing those lines VS restored the packages and built the solution correctly again.无论如何,在删除这些行之后,VS 恢复了软件包并再次正确构建了解决方案。

通过删除以下目录中的内容来清除 Nuget 缓存可能是个好主意: C:\\Users\\{your_username}\\AppData\\Local\\NuGet

Well it's probably a bad way but I found that it works if I just delete the line嗯,这可能是一种糟糕的方式,但我发现如果我只是删除该行,它就可以工作

http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" /> http://go.microsoft.com/fwlink/?LinkID=317567。" HelpKeyword="BCLBUILD2001" />

from the project.csproj , not sure if this is going to cause problems later on but it works for now.从 project.csproj ,不确定这是否会在以后引起问题,但现在可以使用。

All you need is that: Open the Package Manager Console and run this command: Update-Package -reinstall您只需要:打开包管理器控制台并运行以下命令: Update-Package -reinstall

PS : VS2017 and above NuGet Package Manager is included with Visual Studio, no need to install anything else. PS :VS2017 及以上的 NuGet 包管理器包含在 Visual Studio 中,无需安装任何其他东西。

The problem with the functionality of the NuGet package can also be caused by the fact that NuGet package is requiring certain dependency that the project does not meet . NuGet 包的功能问题也可能是因为NuGet 包需要项目不满足的某些依赖项

NuGet package can have a declared dependency in Dependecies section, eg .NETFramework,Version=v.4.6.2 while the project is targeted to an older version ( Target framework: .NET Framework 4.6.1. ). NuGet 包可以在Dependecies部分中声明依赖,例如 .NETFramework,Version=v.4.6.2 而项目针对的是旧版本(目标框架:.NET Framework 4.6.1. )。

Instead of the NuGet system notifying the user of this fact, the project simply does not compile. NuGet 系统没有将这一事实通知用户,而是该项目根本不编译。

In my case, I have different Nuget configurations, and somehow the HintPath in the project file didn't fit.就我而言,我有不同的 Nuget 配置,不知何故项目文件中的 HintPath 不适合。

在此处输入图片说明

Maybe you should check if the HintPath leads to the right NuGetPackages folder.也许您应该检查 HintPath 是否指向正确的 NuGetPackages 文件夹。

You should also check the following entries at the top of the file:您还应该检查文件顶部的以下条目: 在此处输入图片说明

And at the bottom of the file:在文件的底部: 在此处输入图片说明

All these paths should point to the right NuGetPackage folder in your file structure.所有这些路径都应指向文件结构中正确的 NuGetPackage 文件夹。

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

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