1
votes

I have a feed for PowerShell modules in my VSTS project and I am using it as a private gallery, based on this article: https://roadtoalm.com/2017/05/02/using-vsts-package-management-as-a-private-powershell-gallery/

Everything works great when we run this on the machine. I need these modules as part of the release process, so the first task is to register this repo if it doesn't exist and then download and install the latest version of each module. The relevant part of my script is:

Install-PackageProvider -Name NuGet -Confirm:$false -RequiredVersion 2.8.5.208
Get-PSRepository | Where-Object {$_.Name -eq "MyPrivateFeed" -or $_.SourceLocation -eq "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2"} | Unregister-PSRepository
Register-PSRepository -Name "MyPrivateFeed" -SourceLocation "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2" -InstallationPolicy Trusted
$PAT = $(System.AccessToken) | ConvertTo-SecureString -AsPlainText -Force
$VSTSCredentials = New-Object -TypeName PScredential("dummy", $PAT)
Find-Module -Name * -Repository MyPrivateFeed -Credential $VSTSCredentials | Install-Module -Credential $VSTSCredentials

The PowerShell task in the release fails with:

WARNING: Unable to find module repositories.
PackageManagement\Register-PackageSource : The property 'Values' cannot be 
found on this object. Verify that the property exists.
At C:\Program 
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4173 
char:17
+ ...     $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.Power...erPackageSource 
   :RegisterPackageSource) [Register-PackageSource], Exception
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Pack 
   ageManagement.Cmdlets.RegisterPackageSource 

The same exact script works on the same machine when I run it on ISE/Console (with replacing the token with the actual PAT of course) Anyone has any idea what is going on here?

I tried adding -PackageManagementProvider NuGet to Register-PSRepository but that didn't help

1

1 Answers

0
votes

I occasionally see the "Register-PackageSource : The property 'Values' cannot be found on this object. Verify that the property exists." error when attempting to run a "Register-PSRepository" command from the PowerShellGet module (or a "Register-PackageSource" command from the dependent PackageManagement module) when there are no package sources currently registered for the "PowerShellGet" package provider (not even the default "PSGallery").

This appears to happen when an empty file exists under the current user's profile at "%USERPROFILE%\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml". I'm not sure what causes that empty file to be created, but until it's deleted, not even the "Register-PSRepository -Default" command will succeed.

Deleting the file does resolve the error and allows PowerShellGet package sources to be registered again.