4

I have a local package source to mess around with some things. I created a brain-dead package called CoolUtils, adding it using nuget add. You can find it using 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

However, Find-Package can't find it by name, but can find it with wildcards or no name specified:

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

I also can't install it using Install-Package, though I can using nuget.

Clijsters
  • 4,031
  • 1
  • 27
  • 37
SirPentor
  • 1,994
  • 14
  • 24

2 Answers2

5

Cmdlet Find-Package is part of PackageManagement module, while Nuget.exe is one of a dozen of package providers for PackageManagement module.

An analogy (not fully correct) is an application and plugins: Nuget is like one of plug-ins which provides functionality to its application (Find-Package, Install-Package and other cmdlets from PackageManagement).

Despite Nuget can do some package management tasks, in order to work under control of standardized PackageManagement commands you should properly declare ("register") nuget's package locations to make them known for PackageManagement:

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


Now Find-Package can search and Install-Package can install packages from newly registered package source. Full list of known package sources can be retrieved by

Get-PackageSource

maoizm
  • 682
  • 13
  • 17
  • I have done this, and Find-Package is finding my package when I'm using no name or `-Contains mypkg`, but not when I'm using `-Name`. I think it must be specific to the NuGet Provider. When I try the same thing using the PSGallery source (PowerShellGet provider), it works for `Name`, and it spits a no-such-parameter for `Contains`.. The chocolatey provider supports both `Name` and `Contains`... – Paul Hicks Mar 06 '19 at 03:16
  • @PaulHicks That means that search capabilities are delegated to Package providers and this is up to them which search tools they are going to provide to the client – maoizm Jun 17 '21 at 10:45
0

I experienced the same issue and managed to solve it by moving the .nupkg file to the root of the registered local package source, i.e. "C:\projects\packages\"

PS> Get-PackageSource -Name Local

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
Local                            NuGet            False      C:\projects\packages\

PS> Find-Package -Source Local -Name TestCmdlet

Name                           Version          Source           Summary
----                           -------          ------           -------
TestCmdlet                     1.0.0            Local            Package Description