Powershell Find-Package 命令不适用于 nuget v3 包源

Spe*_*ort 6 powershell nuget nugetgallery

正如标题所说,我不能在 nuget v3 url 中使用 Find-Package 命令:

https://api.nuget.org/v3/index.json
Run Code Online (Sandbox Code Playgroud)

如果我运行命令:

Find-Package nuget.versioning -Source https://api.nuget.org/v3/index.json
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,提示找不到匹配项。将命令更改为:

Find-Package nuget.versioning -Source https://www.nuget.org/api/v2
Run Code Online (Sandbox Code Playgroud)

工作正常。

我是否需要升级某些软件才能使其正常工作?我正在运行 Powershell 版本 5,所以我不确定我需要采取哪些步骤来解决这个问题。

mab*_*ead 4

使用 Powershell 5.1,它会按照您的描述失败。但在 PowerShell Core 7 中,它可以正常工作:

\n\n
PS> Find-Package nuget.versioning -Source https://api.nuget.org/v3/index.json -ProviderName NuGet\n\nName                           Version          Source           Summary\n----                           -------          ------           -------\nNuGet.Versioning               4.6.4            nuget.org        NuGet's implementation of Semantic Versioning.\n
Run Code Online (Sandbox Code Playgroud)\n\n

请注意,您可以通过变量检查您的 PowerShell 版本PSVersionTable

\n\n
PS> $PSVersionTable\n\nName                           Value\n----                           -----\nPSVersion                      7.0.0\nPSEdition                      Core\nGitCommitId                    7.0.0\nOS                             Microsoft Windows 10.0.18362\nPlatform                       Win32NT\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0\xe2\x80\xa6}\nPSRemotingProtocolVersion      2.3\nSerializationVersion           1.1.0.1\nWSManStackVersion              3.0\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 PowerShell Core 7 上,您将看到它使用 NuGet 包提供程序的版本 3,因此它支持协议 v3。

\n\n
PS> Get-PackageProvider\n\nName                     Version          DynamicOptions\n----                     -------          --------------\nNuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate\nPowerShellGet            2.2.3.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, Accep\xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n