我们正在使用改进的 Automatic Package Restore恢复丢失的 NuGet 包的过程。
构建时,开始从包源下载时会弹出“恢复”对话框,这是正确的:
我可以看到这些包正在恢复到包文件夹中,但它并没有完成所有这些包的恢复。我收到以下类型的错误:
Error 10 NuGet Package restore failed for project MyProject: System.InvalidOperationException: Unable to find version '6.0.1' of package 'Newtonsoft.Json'.
at NuGet.PackageHelper.ResolvePackage(IPackageRepository repository, String packageId, SemanticVersion version)
at NuGet.VsEvents.PackageRestorer.RestorePackage(PackageReference package)
at NuGet.VsEvents.PackageRestorer.RestorePackages(String packageReferenceFileFullPath, IFileSystem fileSystem)
at NuGet.VsEvents.PackageRestorer.PackageRestore(ProjectPackageReferenceFile projectPackageReferenceFile).
这可能是因为我有多个包源吗?
例如,NuGet 可能在我们的私有(private)包源中搜索“Newtonsoft.Json”,而不是在
nuget.org
中搜索。来源。.nuget/NuGet.config
文件:<configuration>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="private" value="http://privatePackageSource.com/nuget" />
</packageSources>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
我们正在使用 Visual Studio 2013 和 NuGet 2.8.5。
编辑:
使用 Fiddler,我已经确认 NuGet 确实在不正确的源中搜索包。它正在从我的私有(private)存储库中请求以下包。
我还阅读了this post并添加了
activePackageSource
NuGet.config
的部分文件:<configuration>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="private" value="http://privatePackageSource.com/nuget" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
但这并不能解决问题。
最佳答案
出于某种原因,我的 NuGet.config 禁用了 nuget.org 键。我检查了 NuGet 包管理器设置,一切都是正确的。重新启动VS2013,它工作。这是我的 NuGet.config 有效:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="Microsoft and .NET" value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
</activePackageSource>
</configuration>
关于visual-studio-2013 - 自动包恢复 : Unable to find version of package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23928801/