[英]NuGet unable to find the version of a package
运行命令
nuget.exe restore .\MySolution.sln
给出此错误:
无法找到 package“Microsoft.Net.Compilers”的版本“1.0.0”。
其中 package 之前已安装和恢复,但不知何故已损坏。
原来只是通过更新 NuGet 版本
nuget.exe update -self
从 2.8.0 更新到 3.4.4 就足够了,并且该包现在可以正确恢复。
我能够在macOS 上使用以下命令重置我的 NuGet 缓存/索引来解决这个问题:
dotnet nuget locals --clear all
之后我能够成功恢复我的包:
dotnet restore
我遇到了同样的问题,但我需要继续使用nuget.exe
2.8,因为无法升级安装在我们的构建服务器上的 .NET Framework 版本(2.8 是最后一个仍然适用于 .NET 4.0 的版本)。
原因原来是nuget.config
只指向 v3 API。 解决方案是在 v2 API 中添加。 例如,
<configuration>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="nuget v2" value="https://www.nuget.org/api/v2" />
</packageSources>
</configuration>
因为我最近多次偶然发现这个问题,这是我的解决方案:
C:\\Users\\<User>\\AppData\\Roaming\\NuGet\\
NuGet.config
<packageSources>
添加<add key="keyName" value="path to repository">
<packageSources>
。 就我而言,它是一个指向\\\\JENKINS\\nuGet Repository
的网络文件夹所以它应该看起来类似于:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="local" value="\\JENKINS\nuGet Repository" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
如果使用dotnet cli
并基于此文档,则可以使用带有一些选项的dotnet restore
命令,例如-f
、 --no-cache
和--ignore-failed-sources
:
dotnet restore -f --no-cache --ignore-failed-sources
使用此命令,.NET Core 不会在缓存的包中搜索。
我面临着同样的问题,但你所有的答案都没有帮助我。
然后,我发现我的时钟延迟了(那天我换了电脑),我没有意识到这一点。
这个简单的修正使它一切正常。 包版本确实存在,但因为它被认为是“未来”,NuGet 给出了找不到版本 xxx 的错误。
我认为这是一个巨大的错误,因为它不在乎包裹的时间。 如果您有版本列表,则发布日期时间并不重要。
在我们的例子中,我们将 Visual Studio 中的 NuGet 扩展从 3.3.x 升级到 3.4.4。
您可以在菜单Tools → Extensions and Updates → Updates → Visual Studio Gallery 中找到更新。
就我而言,我已将 NuGet 升级到最新版本,但仍然出现错误。
然后我发现,在Solution Root Folder → 'packages' folder ,里面有repositories.config
,打开文件,你会看到所有正在使用的packages.config
:
<repository path="..\Common\Luna.Common\packages.config" />
<repository path="..\Common\Luna.ComponentBehaviors\packages.config" />
<repository path="..\Common\Luna.Data\packages.config" />
<repository path="..\Common\Luna.WPF.ApplicationFramework\packages.config" />
<repository path="..\GuyWire\Luna.Basic.GuyWire\packages.config" />
它正在存储信息1.0.0
:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Iesi.Collections" version="3.1.0.4000" targetFramework="net40" />
<package id="log4net" version="2.0.3" targetFramework="net40" />
<package id="NHibernate" version="1.0.0" targetFramework="net40" />
<package id="uNhAddIns" version="1.0.0" targetFramework="net40" />
</packages>
因为实际上我是通过文件引用DLL文件的,所以我不需要通过NuGet来获取。 我删除了packages.config
文件,然后错误就解决了。
对我来说,解决问题的是在解决方案文件夹中运行以下命令:
nuget restore -NoCache -NonInteractive
我的问题是我将“包源”设置为我自己的特定 NuGet 服务器而不是全部。
清除 Nuget 缓存对我有用。
要从 Visual Studio 执行此操作,只需打开工具 -> 选项 -> Nuget 包管理器 -> 常规,然后单击按钮Clear All Nuget Cache(s)
在Package Sources下,我不得不取消选中Machine Wide Packages: Microsoft and .NET
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.