简体   繁体   English

Azure 上 nuget 还原步骤中来自特定包源的 Nuget 包

[英]Nuget package from specific package source on nuget restore step on Azure

The package I am trying to restore is both on nuget.org and on a 3rd party myget .我试图恢复的包在nuget.org3rd party myget The 3rd party is a higher version (pre-release) that I want to use, however it seems to not even try to locate the myget source for this package since it finds the package on nuget.org except not the version I want resulting in the following error message:第 3 方是我想要使用的更高版本(预发行版),但是它似乎甚至没有尝试找到此包的 myget 源,因为它在 nuget.org 上找到了该包,但不是我想要的版本导致以下错误消息:

##[error]The nuget command failed with exit code(1) and error(Errors in packages.config projects
Unable to find version '2.0.0-dev-00013' of package 'Discord.Addons.Interactive'.
  https://api.nuget.org/v3/index.json: Package 'Discord.Addons.Interactive.2.0.0-dev-00013' is not found on source 'https://api.nuget.org/v3/index.json'.)

The myget is properly configured in my nuget.config, which is in my solution root myget 在我的 nuget.config 中正确配置,它位于我的解决方案根目录中

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Foxbot" value="https://www.myget.org/F/foxbot-discord-addons/api/v3/index.json" />
  </packageSources>
</configuration>

How would I go about making the nuget restore step respect the myget package source for this package?我将如何让 nuget 恢复步骤尊重此包的 myget 包源?

How would I go about making the nuget restore step respect the myget package source for this package?我将如何让 nuget 恢复步骤尊重此包的 myget 包源?

For nuget restore task, there's one option used to control which feeds to use during package restore.对于nuget restore任务,有一个选项用于控制在包还原期间使用哪些提要。

See feeds to use :请参阅要使用的提要

在此处输入图片说明

Different from restoring packages locally , the nuget.config file in solution directory(Devops Repos) won't work until we check the Feeds in my Nuget.config option.本地恢复包不同,解决方案目录(Devops Repos)中的nuget.config文件将无法工作,直到我们检查Feeds in my Nuget.config选项中的Feeds in my Nuget.config

So during that process, nuget actually didn't use your nuget.config file for package source , which caused this issue:所以在这个过程中,nuget 实际上没有将你的nuget.config文件用于package source ,这导致了这个问题:

在此处输入图片说明

Workaround:解决方法:

Configure the Feeds in my Nuget.config like below to make sure nuget will use your Nuget.config file in Solution directory:在我的Nuget.config配置 Feed,如下所示,以确保 nuget 将使用解决方案目录中的Nuget.config文件:

在此处输入图片说明

In addition: If you're using yaml format instead of classic format, you should set feedsToUse: 'config' and nugetConfigPath: 'path/NuGet.config' .另外:如果你使用yaml 格式而不是经典格式,你应该设置feedsToUse: 'config'nugetConfigPath: 'path/NuGet.config'

There is no longer a priority for sources, the fastest one wins.资源不再有优先级,最快的获胜。

Packages are expected to be unique on the id and version, scenarios where feeds contain different variations of the same id/version are NOT supported.包在 ID 和版本上应该是唯一的,不支持提要包含相同 ID/版本的不同变体的情况。

The priority ordering caused performance issues, as the calls to the sources were sequential instead of parallel.优先级排序会导致性能问题,因为对源的调用是顺序而不是并行的。 I would suggest you the following to resolve this issue:我建议您通过以下方式解决此问题:

  • avoid having different packages with the same id/version, or to reconcile these issues before hand by using a single feed where this has already been resolved.避免使用具有相同 ID/版本的不同包,或者通过使用已经解决的单个提要事先协调这些问题。
  • Add a prefix/suffix in the custom feed source在自定义提要源中添加前缀/后缀

If still requires the priority , you could so something like below: Have config something like below:如果仍然需要优先级,你可以像下面这样:配置如下:

  <packageSources>
        <!-- Internal package source comes before NuGet.org proxy -->   
        <add key="my_private_feed" value="Feed1/" priority="1" />
        <add key="Orgnugetorg" value="https://www.nuget.org/api/v2/" priority="2" />
    </packageSources> 

The **PackageDownloader** needs to be adapted that he waits for the download with the highest priority if package sources have different priorities otherwise fastest wins, **PackageDownloader**需要进行调整,如果包源具有不同的优先级,则他等待具有最高优先级的下载,否则最快获胜,

But please be mindful that it would require change in Packagedownloader in your pipeline.但请注意,它需要在您的管道中更改 Packagedownloader。

Additional reference:补充参考:

https://github.com/NuGet/Home/issues/5611 https://github.com/NuGet/Home/issues/5611

NuGet packageSources priority NuGet 包源优先级

Hope it helps.希望能帮助到你。

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

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