项目PROJECT的NuGet包还原失败:无法找到2.0.0版的软件包' Microsoft.Net.Compilers'

时间:2016-12-01 14:09:29

标签: asp.net-mvc visual-studio-2015 nuget-package-restore

我使用Visual Studio 2015的GitHub扩展将我的项目克隆到新计算机上。我尝试恢复包,然后收到一条错误消息:

NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'

我已经查看过有关类似问题的其他一些问题,但这些解决方案都没有对我有用。

我尝试删除packages文件夹,再次打开Visual Studios,然后重建。那并没有解决它。

我尝试在Package Manager Console中手动安装Microsoft.Net.Compilers。

 PM> Install-Package Microsoft.Net.Compilers

我尝试从csproj文件中删除这段代码(这似乎适用于某些人):

    <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>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=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>

我尝试使用

重新安装所有软件包
Update-Package –reinstall

到目前为止,我还没有解决这个问题的运气。任何帮助表示赞赏。

编辑:

I tried the response below and received this error:

Install-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations.
At line:1 char:16
+ Install-Package <<<<  -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org
    + CategoryInfo          : InvalidOperation: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

它还促使我恢复包裹。当我点击恢复时,我得到了和往常一样的错误。

8 个答案:

答案 0 :(得分:14)

根据您的错误消息看起来您正在寻找不再存在的版本,并且无法分辨您选择了哪个Package源。我觉得你正在寻找nuget.org存储库中没有的2.0.0版本。最新版本是2.0.0-rc,它是预发布候选版本。

如果您想获得最新版本,请尝试此命令

Install-Package -Id Microsoft.Net.Compilers -Version 2.0.0-rc -Source nuget.org

如果您需要最新的稳定版本(1.3.2),请尝试此命令

Install-Package -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org

<强>更新 如果仍然无法安装软件包,那么package.config,packages / folder和.csproj文件中的软件包可能不同步

请按照以下步骤执行手动清理

  1. 关闭视觉工作室。
  2. 在记事本或某个文本编辑器中打开.csproj并手动删除与Microsoft.Net.Compilers相关的所有条目
  3. 在记事本或某个文本编辑器中打开packages.config并删除Microsoft.Net.Compilers包的条目
  4. 转到Windows资源管理器中的packages /文件夹并删除Microsoft.Net.Compilers文件夹
  5. 现在启动visual studio并打开解决方案。
  6. 现在尝试再次安装该软件包。
  7. 作为第2步的一部分,您可能必须从.csproj中删除的一些条目是

    <Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />
    
    <NuGetPackageImportStamp></NuGetPackageImportStamp>
    
    <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.3.2\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props'))" />
    </Target>
    

答案 1 :(得分:2)

我在 VS 2019 上也遇到了类似的问题,这个对我有用,只需转到“工具”>“选项”>“NuGet 包管理器”>“常规”并清除所有 NuGet 缓存。

见下图 See the image below

答案 2 :(得分:1)

这可能会有点晚,但仍然可以帮助某个人。当您尝试检入代码并遇到这种错误时,这意味着您已经安装并再次卸载了该软件包,因此您只需要在包含的更改下找到该软件包即可,在我的示例中,使用TFS,并排除或撤消。这将解决问题。

答案 3 :(得分:1)

在全新安装Visual Studio 2017之后,我遇到了类似的错误,必须执行以下操作才能自动成功恢复丢失的NuGet程序包。在VS中,转到“工具>选项> NuGet程序包管理器>程序包源”,并确保显示并检查了适当的程序包源。

请参阅下文。如果在本地计算机上找不到合适的版本,则在顶部添加nuget.org软件包源会告诉VS在线从NuGet下载软件包。

enter image description here

答案 4 :(得分:0)

我知道为什么,它位于C:\ Program Files(x86)\ Microsoft SDKs \ NuGetPackages文件夹中。您之前安装了包。

答案 5 :(得分:0)

我将项目移至与NuGet程序包最初存储在项目中的位置有关的位置,最终我发现这导致该.csproj文件出现问题,这种问题可能不会立即显现。

移动之后,完成NuGet软件包还原后,第二个条目已添加到我的EnsureNuGetPackageBuildImports文件的.csproj目标中,反映了新位置的相对路径。

目标现在如下所示:

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

请注意这两个条目,它们具有packages所在路径的不同路径。这意味着其中一个(第一个是我搬迁项目之前的那个)总是会失败。

修复非常简单。我刚刚从Error中删除了第一个Target节点。

我还发现根Import节点的初始Project节点中存在类似的问题。

我有以下内容:

<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" />
  <Import Project="..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" />

同样,解决方法只是删除错误的Import节点。

答案 6 :(得分:0)

使用旧版本的nuget.exe也可能发生这种错误。例如,如果您下载TFS 2015的agent.zip,则其内部具有版本3.2.1:

\ Agent \ Worker \ Tools \ nuget.exe

该版本可能会出现错误“无法找到软件包'NUnit'的版本'3.7.1'。”使用VS 2015创建的解决方案。(尽管NUnit3TestAdapter.3.9.0不会给出错误)

将nuget.exe更新到5.2可解决此问题。

答案 7 :(得分:0)

这是我的错误:“该项目引用了此计算机上缺少的 NuGet 包。使用 NuGet 包还原来下载它们。”

enter image description here

这是我的解决方案:我必须确保在“管理 Nuget 包”窗口中检查了我的包源。

enter image description here

相关问题