简体   繁体   English

使用-source参数的NuGet Install Packages不会下载nuget.org

[英]NuGet Install Packages with -source parameter isn't downloading nuget.org

My company hosts our own internal NuGet package repository for us to upload our own private, proprietary packages to. 我公司拥有自己的内部NuGet包存储库,供我们上传我们自己的私有专有包。 We still use the official NuGet.org repository for pulling down all the public packages. 我们仍然使用官方的NuGet.org存储库来下载所有公共包。 We also enable Package Restore in our projects to allow our build to download missing packages. 我们还在项目中启用了Package Restore ,以允许我们的构建下载丢失的包。

We have added our own NuGet repo to the list in Tools > Library Package Manager > Package Manager Settings > Package Sources and we have also left the default one ( NuGet official package source ) in the list as well. 我们在Tools > Library Package Manager > Package Manager Settings > Package Sources中将我们自己的NuGet仓库添加到列表中,我们也在列表中保留了默认值( NuGet官方包源 )。 We also have our own repo in the NuGet.targets file as a PackageSource element. 我们在NuGet.targets文件中也有自己的repo作为PackageSource元素。 The offical repo is not included as a PackageSource in that file though. 然而,官方repo 包含在该文件中作为PackageSource

This has worked for us for several months. 这对我们来说已经有好几个月了。 When we release new version of our own packages to our repo, they are visible to the projects. 当我们将自己的软件包的新版本发布到我们的仓库时,它们对项目是可见的。 Also, when new public packages become available, our projects haven't had any problems finding them on nuget.org . 此外,当新的公共包可用时,我们的项目在nuget.org上找到它们没有任何问题。

Just recently however, the build has started failing to download packages from the official repo. 然而就在最近,构建已经开始无法从官方仓库下载包。 When I build the solution, the output contains the following line for every project which references missing packages we aren't hosting on our own repo: 当我构建解决方案时,输出包含每个项目的以下行,它引用我们不在我们自己的repo上托管的缺少的包:

C:\code\MyCodebase\.nuget\nuget.targets(79,9): error MSB3073: The command ""C:\code\MyCodebase\.nuget\nuget.exe" install "C:\code\MyCodebase\MyProject\packages.config" -source "http://nuget.example.com/repo/" -o "C:\code\MyCodebase\packages"" exited with code -1.

If I run that command from the command line myself, I see this output in bright red: 如果我自己从命令行运行该命令,我会看到此输出为鲜红色:

Unable to find version '2.5.10.11092' of package 'NUnit'.
Unable to find version '1.2.0' of package 'Common.Logging'.

I assume this is happening because our repo doesn't contain any NUnit packages and the -Source parameter isn't using the official repo. 我假设发生了这种情况,因为我们的repo不包含任何NUnit包, -Source参数不使用官方repo。

My question is: Why did it used to work? 我的问题是:为什么以前工作? Am I crazy? 我疯了吗? Or has something in the NuGet.exe behavior changed in a recent update? 或者在最近的更新中是否更改了NuGet.exe行为? I was under the impression that NuGet always used the official repo as a final fallback and it seemed that way up until yesterday. 我的印象是,NuGet 总是使用官方回购作为最后的后备,直到昨天它似乎一直如此。

Is the only solution to add the official NuGet repo into the NuGet.targets file? 是将官方NuGet repo添加到NuGet.targets文件中的唯一解决方案吗? What is the best way to handle having private and public package dependencies in the same solution? 在同一解决方案中处理私有和公共包依赖关系的最佳方法是什么? I would like to avoid having to upload all the public packages we use to our own repo. 我想避免将我们使用的所有公共包上传到我们自己的仓库。

A comment in nuget.target states the following, you need to add the official feed to the list nuget.target中的注释说明如下,您需要将官方订阅源添加到列表中

<!-- Package sources used to restore packages. <! - 用于恢复包的包源。 By default, registered sources under %APPDATA%\\NuGet\\NuGet.Config will be used --> 默认情况下,将使用%APPDATA%\\ NuGet \\ NuGet.Config下的注册源 - >

<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list --> <! - 如果指定了包源且未显示在列表中,则将排除官方NuGet包源(https://nuget.org/api/v2/) - >

Did you recently clear your nuget cache from %appdata%\\local\\nuget\\cache? 您最近是否从%appdata%\\ local \\ nuget \\ cache清除了您的nuget缓存? When I tried the steps on my box it worked installing the dependency if the missing package (from the local repo) is in the local nuget cache. 当我尝试我的盒子上的步骤时,如果缺少的包(来自本地存储库)位于本地nuget缓存中,则它可以安装依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM