我们正在使用改进的Automatic Package Restore进程来恢复丢失的NuGet包。
构建时,恢复对话框会在开始从包源下载时弹出,这是正确的:
我可以看到软件包正在恢复到packages文件夹中,但它还没有完成所有软件包的恢复。我收到以下类型的错误:
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可能会在我们的私人包源中搜索' 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确实在不正确的源中搜索包。它从我的私人存储库请求以下包。
我还阅读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>
但它并没有解决问题。
答案 0 :(得分:18)
它确实被全局NuGet.config文件(C:\ Users \ UserName \ AppData \ Roaming \ NuGet \ NuGet.config)覆盖。重新启动Visual Studio似乎清除了它。
答案 1 :(得分:10)
出于某种原因,我的NuGet.config禁用了nuget.org密钥。我检查了NuGet Package Manger设置,一切都正确。重新启动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>
答案 2 :(得分:1)
有同样的错误,在我的情况下是一个nuget restore命令,然后再为我修复它