我使用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
它还促使我恢复包。当我点击恢复时,我得到了和往常一样的错误。
根据您的错误消息,您似乎正在寻找不再存在的版本,并且无法分辨您选择的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文件之间的包可能不同步
请按照以下步骤执行手动清理
作为第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>
这可能有点晚,但它仍然会帮助某人。当您尝试检入代码并且出现此类错误时,这意味着您已经安装了软件包并再次将其卸载,因此您只需要在包含的更改下找到软件包,在我的示例中我使用TFS,并排除或撤消。这将解决问题。
我移动了我的项目与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
节点。
我知道为什么,它位于C:\ Program Files(x86)\ Microsoft SDKs \ NuGetPackages文件夹中。您之前安装了包。