使用Azure DevOps Artifacts feed和NuGet上游源进行Install-Package安装失败。

3

问题

我想从公共存储库中安装一个包。我希望使用PackageSource External。这是一个Azure DevOps Artifacts Feed,配置了NuGet Gallery作为上游源。由于NuGet Gallery是一个上游源,因此我的包请求应该通过Artifacts传递并由上游源满足,但实际上出现错误,指出没有匹配项。

另一方面,如果我使用直接指向NuGet Gallery的PackageSource提交相同的请求,则可以正常工作。是否Artifacts中的Upstream source功能有问题?


enter image description here

包源

[D:\MySandboxes\TFS\Development\DevOps\]
>Get-PackageSource

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
Microsoft Visual Studio Offli... NuGet            False      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Internal                         NuGet            False      http://azuredevops/Development/_packaging/Internal/nuget/v3/index.json
External                         NuGet            False      http://azuredevops/Development/_packaging/External/nuget/v3/index.json
MyNuGet                          NuGet            False      https://www.nuget.org/api/v2
PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2

使用Azure DevOps Artifacts软件包源安装软件包(失败)

[D:\MySandboxes\TFS\Development\DevOps\]
>Install-Package Resta.UriTemplates -Source External -Destination "."
Install-Package : No match was found for the specified search criteria and package name 'Resta.UriTemplates'. Try Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Install-Package Resta.UriTemplates -Source External -Destination "."
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

使用NuGet Gallery包源安装软件包(成功)

[D:\MySandboxes\TFS\Development\DevOps\]
>Install-Package Resta.UriTemplates -Source MyNuGet -Destination "."
The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'MyNuGet'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "No"): a

Name                           Version          Source           Summary
----                           -------          ------           -------
Resta.UriTemplates             1.3.0            MyNuGet          .NET implementation of the URI template spec (RFC6570). Supports up to level 4 template expressions.

2个回答

1
在我的端上,“上游源”功能运行良好。然而,在安装软件包时我没有收到此推广信息。
The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'MyNuGet'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "No"): a

这似乎与您的本地安全设置有关。我不知道如何启用或禁用。但是,根据您的描述和情况,在我看来,我想知道在使用Azure DevOps Artifacts软件包源安装软件包时是否存在跳转。
由于与直接连接NuGet Gallery不同,您需要首先访问Azure DevOps Artifacts Feed,然后通过上游源获取该软件包。您无法选择信任信息,它选择默认值(默认值为“否”)。最后,您无法安装该软件包。
您可以关闭本地安全设置并再次尝试,这可能会奏效。如果由于策略原因,您无法关闭它。
作为解决方法,您可以创建一个需要关闭上游源的新Feed,并将您的软件包上传到该Feed中作为软件包源。

感谢您的回复,Patrick!经过一些额外的测试并改用nuget.exe命令来安装包,现在似乎可以正常工作了。我猜测我的Install-Package cmdlet可能是一个旧版本,有点难搞。我将把这个问题写成答案,但我仍然不完全确定为什么Install-Package失败而nuget.exe install却能成功。 - Zam

0
所以,在进行了一些额外的测试之后,我发现使用nuget.exe CLI可以解决Install-Command命令未能正常工作的问题。
不幸的是,我仍然不完全确定为什么会出现这种行为。
以下是我的 Install-Package 版本。
>Get-Command -name 'Install-Package'

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Install-Package                                    1.4.3      PackageManagement

还有我的版本的nuget.exe

>nuget
NuGet Version: 5.2.0.6090

最后,这是nuget.exe命令成功的输出。

[C:\Users\srz\]
>nuget install Microsoft.Extensions.Primitives -Version 3.0.1 -Source "External"
Feeds used:
  C:\Users\srz\.nuget\packages\
  http://azuredevops/Development/_packaging/External/nuget/v3/index.json



Attempting to gather dependency information for package 'Microsoft.Extensions.Primitives.3.0.1' with respect to project 'C:\Users\srz', targeting 'Any,Version=v0.0'
Gathering dependency information took 651.6 ms
Attempting to resolve dependencies for package 'Microsoft.Extensions.Primitives.3.0.1' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.Extensions.Primitives.3.0.1'
Resolved actions to install package 'Microsoft.Extensions.Primitives.3.0.1'
Retrieving package 'Microsoft.Extensions.Primitives 3.0.1' from 'External'.
  GET http://azuredevops/Development/_packaging/abc123/nuget/v3/flat2/microsoft.extensions.primitives/3.0.1/microsoft.extensions.primitives.3.0.1.nupkg
  OK http://azuredevops/Development/_packaging/abc123/nuget/v3/flat2/microsoft.extensions.primitives/3.0.1/microsoft.extensions.primitives.3.0.1.nupkg 229ms
Installing Microsoft.Extensions.Primitives 3.0.1.
Adding package 'Microsoft.Extensions.Primitives.3.0.1' to folder 'C:\Users\srz'
Added package 'Microsoft.Extensions.Primitives.3.0.1' to folder 'C:\Users\srz'
Successfully installed 'Microsoft.Extensions.Primitives 3.0.1' to C:\Users\srz
Executing nuget actions took 635.5 ms

似乎与 nuget.exeInstall-Package 命令无关。有时,源可能不会立即更新,需要一些时间 - 可能需要一个小时 - 才能从上游软件包源获取更新。 - AhmadYo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接