Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish-Module from Azure DevOps will not publish to a V3 Nuget Repository when a module has RequiredModules #551

DillonFlohr opened this issue Nov 18, 2019 · 0 comments


Copy link

@DillonFlohr DillonFlohr commented Nov 18, 2019

Steps to reproduce

This is done by an Azure Agent: vs2017-win2016

#Setup Variables
$user = "{authorized email}"
$apikey = "{api key generated to interact with Azure DevOps Artifact Repository}"
$nuget_path = "{repository name}/_packaging/Production/nuget/v3/index.json"
$nuget_path_v2 = "{repository name}/_packaging/Production/nuget/v2"

#Generate PSCredentials
$apikeycred = ConvertTo-SecureString $apikey -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($user, $apikeycred)

#Regeister the NuGet
$registerParams = @{
    Name  = "NugetName"
    InstallationPolicy = "Trusted"
    SourceLocation = $nuget_path
    PublishLocation = $nuget_path
    Credential = $creds
Register-PSRepository @registerParams

#In a for-loop to publish each module in our master branch
Publish-Module -Name $source_code_artifact\modules\$module -Repository NugetName -NuGetApiKey $apikey

Expected behavior

Publish-Module will publish to the NuGet repo

Actual behavior

Microsoft.PowerShell.Core\Test-ModuleManifest : The specified RequiredModules entry 'MyModule' in the module 
2019-11-18T15:35:14.9711782Z manifest 'C:\Users\VssAdministrator\AppData\Local\Temp\20369173\AutomationMetrics\AutomationMetrics.psd1' is invalid. 
2019-11-18T15:35:14.9712043Z Try again after updating this entry with valid values.
2019-11-18T15:35:14.9712483Z At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:10771 char:27
2019-11-18T15:35:14.9712865Z + ... oduleInfo = Microsoft.PowerShell.Core\Test-ModuleManifest -Path $mani ...
2019-11-18T15:35:14.9713228Z +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-11-18T15:35:14.9713603Z     + CategoryInfo          : ObjectNotFound: (C:\Users\VssAdm...ionMetrics.psd1:String) [Test-ModuleManifest], Direct 
2019-11-18T15:35:14.9713969Z    oryNotFoundException
2019-11-18T15:35:14.9714356Z     + FullyQualifiedErrorId : Modules_InvalidRequiredModulesinModuleManifest,Microsoft.PowerShell.Commands.TestModuleM 
2019-11-18T15:35:14.9714722Z    anifestCommand

Additional Info

I tried install the modules before hand as per this issue:

But that results in the error:

2019-11-18T16:44:00.3012235Z Publish-PSArtifactUtility : PowerShellGet cannot resolve the module dependency 'QueryDatabases' of the module 
2019-11-18T16:44:00.3012860Z 'AutomationMetrics' on the repository 'NugetName'. Verify that the dependent module 'QueryDatabases' is available in the 
2019-11-18T16:44:00.3012931Z repository 'NugetName'. If this dependent module 'QueryDatabases' is managed externally, add it to the 
2019-11-18T16:44:00.3013470Z ExternalModuleDependencies entry in the PSData section of the module manifest.
2019-11-18T16:44:00.3013685Z At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:10944 char:17
2019-11-18T16:44:00.3014333Z + ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
2019-11-18T16:44:00.3014519Z +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-11-18T16:44:00.3014932Z     + CategoryInfo          : InvalidOperation: (:) [Publish-PSArtifactUtility], InvalidOperationException
2019-11-18T16:44:00.3015130Z     + FullyQualifiedErrorId : UnableToResolveModuleDependency,Publish-PSArtifactUtility

I believe this error is due to PowerShellGet not interacting nicely with V3 Nuget repositories. I can not use V2 because when I do it opens an interactive session and requires a code to be submitted to a website. I do use V2 Nuget to do a Find-Module to get the current versions of the modules on the Repo because Find-Module does not play nicely with V3.

$modules_in_nuget = Find-Module -Repository "MyRepoV2" -Credential $creds

I've confirmed that the PowerShellGet installed on my azure worker is 2.2.1.

Any thoughts would be appreciated. Getting this set up in the first place because of how finicky PowerShell is with V2/V3 of Nuget was such a hassle. And now, because PowerShellGet requires a V2 connection to find the RequiredModules in the Repo, and Publish-Module requires a V3 connection to avoid the interactive authentication session, and the V3 connection is passed down to PowerShellGet by Publish-Module. It seems like utilizing RequiredModules in my pipeline is impossible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.