Skip to content

Pack step fails if the module requires a module that in turn requires another module #447

@ykuijs

Description

@ykuijs

Problem description

I create a new module based on Sampler using this code:

When I configure this module to require a module that in turns requires another module, the Pack step fails with the error that the dependency cannot be resolved. When I remove the entry from the RequiredModules property or add modules that do not have any RequiredModules themselves, all works well.

I have traced back the error to these lines of code:

if (!([Microsoft.PowerShell.Commands.ModuleSpecification]$module | Find-Module -repository output -ErrorAction SilentlyContinue))
{
# Replace the module by first (path & version) resolved in PSModulePath
$module = Get-Module -ListAvailable -FullyQualifiedName $module | Select-Object -First 1
if ($Prerelease = $module.PrivateData.PSData.Prerelease)
{
$Prerelease = "-" + $Prerelease
}
Write-Build Yellow (" Packaging Required Module {0} v{1}{2}" -f $Module.Name, $Module.Version.ToString(), $Prerelease)
if ($PublishModuleWhatIf)
{
$PublishModuleParams['WhatIf'] = $True
}
# Release notes will be used from module manifest
Publish-Module -Repository output -ErrorAction SilentlyContinue -Path $module.ModuleBase
}

These lines are causing the issue. When I remove them, the Pack step runs as expected. So, not sure why the Required Modules need to get published before publishing the actual module.

Verbose logs

Built module's Manifest found at C:\Temp\MySimpleModule\output\module\MySimpleModule\1.23.1108.1\MySimpleModule.psd1
  Packaging Required Module DscBuildHelpers v0.2.1
ERROR: PowerShellGet cannot resolve the module dependency 'xDscResourceDesigner' of the module 'DscBuildHelpers' on the repository 'output'. Verify that the dependent module 'xDscResourceDesigner' is available in the repository 'output'. If this dependent 
module 'xDscResourceDesigner' is managed externally, add it to the ExternalModuleDependencies entry in the PSData section of the module manifest.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:10990 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At C:\Temp\MySimpleModule\output\RequiredModules\Sampler\0.117.0\tasks\release.module.build.ps1:246 char:1
+ task package_module_nupkg {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Build FAILED. 9 tasks, 1 errors, 0 warnings 00:00:10.1465554
Publish-PSArtifactUtility : PowerShellGet cannot resolve the module dependency 'xDscResourceDesigner' of the module 'DscBuildHelpers' on the repository 'output'. Verify that the dependent module 'xDscResourceDesigner' is available in the repository 'outpu
t'. If this dependent module 'xDscResourceDesigner' is managed externally, add it to the ExternalModuleDependencies entry in the PSData section of the module manifest.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:10990 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Publish-PSArtifactUtility], InvalidOperationException
    + FullyQualifiedErrorId : UnableToResolveModuleDependency,Publish-PSArtifactUtility

How to reproduce

  1. Create a new module
$newSampleModuleParameters = @{
    DestinationPath   = 'C:\Temp'
    ModuleType        = 'SimpleModule'
    ModuleName        = 'MySimpleModule'
    ModuleAuthor      = 'My Name'
    ModuleDescription = 'MySimpleModule Description'
}

New-SampleModule @newSampleModuleParameters
  1. Edit the module PSD1 file in the source folder and replace line 54 (RequiredModules) with RequiredModules = @('DscBuildHelpers', @{ModuleName='DscBuildHelpers'; RequiredVersion='0.2.1'; GUID='23ccd4bf-0a52-4077-986f-c153893e5a6a'})
  2. Run the .\build.ps1 -Tasks noop -ResolveDependency to download all dependencies
  3. Then run the .\build.ps1 -Tasks Pack command. This will fail with the specified error.

Expected behavior

Create a NuGet package successfully

Current behavior

The code throws the mentioned error and fails.

Suggested solution

Not sure why the earlier mentioned lines are even in there. When I remove them, the Pack steps completes successfully and a package is created.

Operating system the target node is running

OsName               : Microsoft Windows 11 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage           : en-US
OsMuiLanguages       : {en-US, en-GB, nl-NL}

PowerShell version and build the target node is running

Name                           Value                                                                                                                                                                                                                           
----                           -----                                                                                                                                                                                                                           
PSVersion                      5.1.22621.2428                                                                                                                                                                                                                  
PSEdition                      Desktop                                                                                                                                                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                         
BuildVersion                   10.0.22621.2428                                                                                                                                                                                                                 
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                 
WSManStackVersion              3.0                                                                                                                                                                                                                             
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                             
SerializationVersion           1.1.0.1

Module version used

0.117.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions