NuGet软件包还原项目失败:无法找到软件包'Microsoft.Net.Compilers'的2.0.0版本 [英] NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'
问题描述
我使用Visual Studio 2015的GitHub扩展将项目克隆到新计算机上.我尝试还原软件包,但收到一条错误消息:
I used the GitHub extension of Visual Studio 2015 to clone my project onto a new computer. I try to restore packages and I get an error that says:
NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'
我已经研究了有关类似问题的其他一些问题,但是这些解决方案中没有一个对我有用.
I've looked into some other questions about similar issues, but none of those solutions have worked for me yet.
我尝试删除程序包文件夹,再次打开Visual Studio,然后重新构建.那没有解决.
I tried deleting the packages folder, opening up up Visual Studios again and then rebuilding. That didn't resolve it.
我尝试在程序包管理器控制台中手动安装Microsoft.Net.Compilers.
I tried manually installing Microsoft.Net.Compilers in Package Manager Console.
PM> Install-Package Microsoft.Net.Compilers
我尝试从csproj文件中删除这段代码(这似乎对某些人有用):
I tried removing this bit of code from the csproj file (this seemed to work for some):
<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>
我尝试使用重新安装所有软件包
I tried reinstalling all packages with
Update-Package –reinstall
到目前为止,我还没有解决这个问题的运气.任何帮助表示赞赏.
So far I haven't had any luck resolving the issue. Any help is appreciated.
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
它也提示我还原软件包.当我点击恢复时,我得到了和往常一样的错误.
It also prompted me to restore packages. When I hit restore, I got the same error as usual.
推荐答案
根据错误消息,您似乎正在寻找一个不再存在的版本,并且无法确定您选择了哪个Package Source.我觉得您正在寻找的版本2.0.0在nuget.org存储库中不可用.最新的是2.0.0-rc,它是预发行版本.
Based on your error message looks like you are looking for a version that no longer exists and cannot tell which Package source you have selected. I feel like you are looking for version 2.0.0 which is not available in nuget.org repository. The latest one is 2.0.0-rc and it is pre release candidate.
如果要获取最新版本,请尝试使用此命令
Please try this command if you want to get the latest version
Install-Package -Id Microsoft.Net.Compilers -Version 2.0.0-rc -Source nuget.org
如果您想要最新的稳定版本(1.3.2),请尝试使用此命令
If you want the latest stable version (1.3.2), try this command
Install-Package -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org
更新 如果仍然无法安装该软件包,则该软件包可能在packages.config,packages/文件夹和.csproj文件之间不同步
UPDATE If the package still cannot be installed, then that package may be out of sync between packages.config, packages/ folder and .csproj file
请按照以下步骤进行手动清理
Please follow these steps to perform manual cleanup
- 关闭Visual Studio.
- 在记事本或某些文本编辑器中打开.csproj,然后手动删除与Microsoft.Net.Compilers相关的所有条目
- 在记事本或某些文本编辑器中打开packages.config,并删除Microsoft.Net.Compilers软件包的条目
- 转到Windows资源管理器中的"packages/"文件夹,然后删除Microsoft.Net.Compilers文件夹
- 现在启动Visual Studio并打开解决方案.
- 现在尝试再次安装该软件包.
作为第2步的一部分,您可能需要从.csproj中删除的某些条目是这些
Some of the entries that you may have to remove from .csproj as part of step 2 are these
<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>
这篇关于NuGet软件包还原项目失败:无法找到软件包'Microsoft.Net.Compilers'的2.0.0版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!