添加新程序包时,NuGet使用无效的提要

时间:2019-12-06 13:12:26

标签: xamarin nuget

我一直在为NuGet使用公共和私人提要,并且已将它们添加到项目根目录的Nuget.Config文件中:

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="ligetFeed" value="http://graymini.local:9011/api/v3/index.json" protocolVersion="3" />       
  </packageSources>
</configuration>

运行nuget restore可以正常工作,并且可以同时从nuget.org和我的私人提要中恢复软件包,但是尝试从nuget.org中添加新的nuget时却失败了,因为它使用了私人提要而不是nuget。 org。我一直在尝试通过nuget install <package>从Visual Studio(Mac)和命令行添加它,但是发生了同样的事情。

输出看起来像这样:

Feeds used:
  https://api.nuget.org/v3/index.json
  http://privatefeed.local:9011/api/v3/index.json

Installing package 'Polly' to '/Users/user/Documents/MyProject'.
  CACHE https://api.nuget.org/v3/registration4-gz-semver2/polly/index.json
  GET http://privatefeed.local:9011/api/v3/registration/polly/index.json
An error was encountered when fetching 'GET http://privatefeed.local:9011/api/v3/registration/polly/index.json'. The request will now be retried.
mono-io-layer-error (-1)
  GET http://privatefeed.local:9011/api/v3/registration/polly/index.json
An error was encountered when fetching 'GET http://privatefeed.local:9011/api/v3/registration/polly/index.json'. The request will now be retried.
mono-io-layer-error (-1)
  GET http://privatefeed.local:9011/api/v3/registration/polly/index.json
An error occurred while retrieving package metadata for 'Polly' from source 'ligetFeed'.
  mono-io-layer-error (-1)

请注意,它尝试使用GET http://privatefeed.local:9011/api/v3/registration/polly/index.json而不是api.nuget.org

是否需要任何其他步骤? NuGet如何决定要使用哪种提要?

通过从Nuget.Config中删除私有供稿条目,添加了包,然后重新添加供稿并还原,我设法很好地添加了包,但是从长远来看,这似乎并不正确。

2 个答案:

答案 0 :(得分:0)

不幸的是,无法为供稿设置 OPTIONAL 优先级来解决该问题。我希望可以按照以下步骤进行操作:

<packageSources>
    <!-- Internal package source comes before NuGet.org proxy -->   
    <add key="my_private_feed" value="http://internal-server:8081/repository/private_feed1/" priority="1" />
    <add key="cache_nugetorg" value="https://www.nuget.org/api/v2/" priority="2" />
</packageSources> 

但是,它不支持。从this issue link,我知道:

  

这是设计使然,源是无序的,并且按照最快响应的顺序搜索它们,而不是按照它们在文件中显示的顺序进行搜索。

顺便说一句,使用nuget.orgactivePackageSource来设置disabledPackageSources禁用是一种不完善的方法。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Chuck Norris Feed" value="https://www.myget.org/F/chucknorris" />
  </packageSources>
  <disabledPackageSources>
    <add key="nuget.org" value="true" />
  </disabledPackageSources>
  <activePackageSource>
    <add key="Chuck Norris Feed" value="https://www.myget.org/F/chucknorris" />
  </activePackageSource>
</configuration>

但是,这种方式也无法实现。我还发现this issue link提出了优先方法作为建议。

最后,将来我会期待这种方法。

答案 1 :(得分:0)

原来是单声道和mDNS(.local)的问题。我一直在使用带有LiGet的Nuget Feed的Mac OS,您可能知道,您可以像使用name.local一样使用IP或graymini.local访问网络上的任何其他Mac >

从{p>替换NuGet.Config中的feed后

<add key="ligetFeed" value="http://graymini.local:9011/api/v3/index.json" protocolVersion="3" /> 

<add key="ligetFeed" value="http://22.33.444.555:9011/api/v3/index.json" protocolVersion="3" /> 

一切似乎都正常。尝试从私有供稿中获取新软件包将返回NotFound而不是出现mono-io-layer-error错误,并且它将继续从nuget.org中正确地获取它。

  GET https://api.nuget.org/v3/registration4-gz-semver2/polly/index.json
  GET http://22.33.444.555:9011/api/v3/registration/polly/index.json
  NOTFOUND http://22.33.444.555:9011/api/v3/registration/polly/index.json 
  OK https://api.nuget.org/v3/registration4-gz-semver2/polly/index.json