在Visual Studio 2017中无法恢复NuGet包

时间:2017-08-23 06:08:19

标签: visual-studio-2017 nuget-package nuget-package-restore

我有Asp.netCore解决方案在Visual Studio 2015上工作正常,然后我转移到Visual Studio 2017。现在的问题是,在Visual Studio 2017每个nuget包上都有黄色感叹号。以下是迄今为止我尝试过的解决方案。

我正在使用Visual Studio Version: 15.3.1

  • 以“管理员”身份运行并恢复包。
  • 来自Clear All Nugget Cache(s)
  • Tools > options > NuGet Package Manager >并再次恢复Nuget。

You can see yellow mark on every nuget package

注意:我已经搜索并找到了以下解决方案并尝试但未解决我的问题。

Solution 1

4 个答案:

答案 0 :(得分:14)

我在这里找到了另一个问题的答案,并且应该归功于@AxelWass,虽然他并没有特别关注它,但它绝对解决了这个问题。上面的答案没有。

我有同样的问题并通过在文本编辑器中打开项目并删除以下部分来解决它:

<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.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
   <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>

一旦删除它,它将解决VS2017和PM似乎无法解决的噩梦问题。我也遇到过多次 - 特别是当我在同一个解决方案目录中混合了很多项目时。

答案 1 :(得分:7)

Microsoft Installing and reinstalling packages with package restore Documentation中所述,您应该Update-Package -reinstall

  

Update-Package -reinstall -ProjectName <project>命令在哪里    是出现的受影响项目的名称   Solution Explorer。单独使用 Update-Package -reinstall 进行恢复   解决方案中的所有包。

答案 2 :(得分:0)

我在config/environments/development.rb中发现错误的配置。我不知道为什么,在此文件中,我当前的项目不包括在内。

您可以在config.asset.debug = false

中看到运行此命令的全局配置

nuget.config

答案 3 :(得分:0)

默认情况下,Visual Studio的新安装未将软件包源配置为在线搜索软件包。那就是问题所在。

我通过stackoverflow链接https://stackoverflow.com/a/32360953/1503372找到了更多的答案。

该答案提到使用“ https://www.nuget.org/api/v2” URL来还原软件包。当我在Visual Studio 2017中打开程序包管理器控制台时,我发现它仅从我的PC搜索程序包(脱机搜索)。

然后我添加了“ https://www.nuget.org/api/v2” URL作为还原程序包的源,并且可以正常工作。

请按照以下步骤添加软件包源。

  1. Right click project > Manage nuget package and you will see "package source label".

  2. Add highlighted URL to package source.

  3. Select "All" as package source.

将Visual Studio配置为在线搜索软件包后,所有软件包都将恢复。

相关问题