为什么 Find-Package 在我的本地包源上找不到按名称的包

Sir*_*tor 4 powershell package-managers powershellget

我有一个本地包源来处理一些事情。我创建了一个名为 的脑死包CoolUtils,并使用nuget add. 您可以使用 nuget 找到它:

PS> nuget list -source E:\nuget-repo-test-01\
CoolUtils 2.0.20171024.1

PS> nuget list coolutils -source E:\nuget-repo-test-01\
CoolUtils 2.0.20171024.1
Run Code Online (Sandbox Code Playgroud)

但是,Find-Package无法按名称找到它,但可以使用通配符或未指定名称找到它:

PS> Find-Package -Source E:\nuget-repo-test-01\

Name                           Version          Source                           Summary
----                           -------          ------                           -------
CoolUtils                      2.0.20171024.1   E:\nuget-repo-test-01\           Test package with dumb scripts.

PS> Find-Package *cool* -Source E:\nuget-repo-test-01\

Name                           Version          Source                           Summary
----                           -------          ------                           -------
CoolUtils                      2.0.20171024.1   E:\nuget-repo-test-01\           Test package with dumb scripts.

PS> Find-Package CoolUtils -Source E:\nuget-repo-test-01\
Find-Package : No match was found for the specified search criteria and package name 'CoolUtils'. Try Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Find-Package CoolUtils -Source E:\nuget-repo-test-01\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
Run Code Online (Sandbox Code Playgroud)

我也无法使用 安装它Install-Package,但我可以使用nuget.

mao*_*izm 5

CmdletFind-PackagePackageManagement模块的一部分,同时Nuget.exe也是模块的十几个包提供者之一PackageManagement

一个类比(不完全正确)是一个应用程序和插件: Nuget就像一个插件,为其应用程序提供功能(Find-PackageInstall-Package以及来自 PackageManagement 的其他 cmdlet)。

尽管Nuget可以执行一些包管理任务,但为了在标准化PackageManagement命令的控制下工作,您应该正确声明(“注册”)nuget 的包位置以使它们为人所知PackageManagement

Register-PackageSource -name MyPackages -location E:\nuget-repo-test-01 -provider Nuget


现在Find-Package可以Install-Package从新注册的包源中搜索并安装包。可以通过以下方式检索已知包源的完整列表

Get-PackageSource