Powershell Find-Package command doesn't work with nuget v3 package source

坚强是说给别人听的谎言 提交于 2021-02-08 19:23:27

问题


As the title says I cannot use the Find-Package command with the nuget v3 url:

https://api.nuget.org/v3/index.json

If I run the command:

Find-Package nuget.versioning -Source https://api.nuget.org/v3/index.json

I get an error that no match was found. Changing the command to:

Find-Package nuget.versioning -Source https://www.nuget.org/api/v2

Works fine.

Do I need to upgrade some software to get this to work? I'm running Powershell version 5 so I'm not sure what steps I need to take to fix this.


回答1:


With Powershell 5.1, it fails as you described. But with PowerShell Core 7, it works correctly:

PS> Find-Package nuget.versioning -Source https://api.nuget.org/v3/index.json -ProviderName NuGet

Name                           Version          Source           Summary
----                           -------          ------           -------
NuGet.Versioning               4.6.4            nuget.org        NuGet's implementation of Semantic Versioning.

Note that you can check for your PowerShell version through the PSVersionTable variable:

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

On PowerShell Core 7, you will see that it uses version 3 of the NuGet package provider, thus it supports protocol v3.

PS> Get-PackageProvider

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            2.2.3.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, Accep…


来源:https://stackoverflow.com/questions/54367822/powershell-find-package-command-doesnt-work-with-nuget-v3-package-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!