Getting "cannot find path" error using Install-Package
Background
I was recently trying to use PowerShelGet Install-Package
to install a module from an Azure DevOps Artifacts hosted PowerShell Gallery using the following script
1# For authentication use a PAT as the password, UID can be anything
2$PATcreds = Get-Credential
3Register-PSRepository -Name BM -SourceLocation 'https://pkgs.dev.azure.com/<org>/_packaging/PowerShell/nuget/v2' -PublishLocation 'https://pkgs.dev.azure.com/<org>/_packaging/PowerShell/nuget/v2' -InstallationPolicy Trusted
4Install-Package BlackMarble.Package -Source BM -Credential $PATcreds
The script did not work I was getting the error
Install-Package : Cannot find the path 'C:\Users<user>\AppData\Local\Temp\936930114\BlackMarble.Package\BlackMarble.Package.0.3.79\BlackMarble.Package.psd1' because it does not exist.
You could see a download progress bar that suggested the download had occurred, but no module was installed.
Solution
Turns out the answer was to not register the repository, but to use a URL in the -Source
parameter to Install-Package
.
1Install-Package BlackMarble.Package -Source https://pkgs.dev.azure.com/<org>/_packaging/PowerShell/nuget/v2 -Credential $PATcreds
It sort of makes sense that there could be a bug such that URLs work and aliases, added via a register-psrepository
, do not. Maybe a bug?
However, more strangely I have found that if the alias is registered the the Install-Package
fails even if a URL is used. The complete solution is therefore to first unregister-psrepository
the alias that match the URL you wish to use before running the Install-Package
command.
All very strange