PowerShell / PowerShellGet

This module provide functions used with PowerShellGet v3 to provide compatibility with scripts expecting PowerShellGet v2
MIT License
49 stars 13 forks source link

"Update-ModuleManifest -RequiredModule" complains about invalid manifest #67

Open Kuxe opened 4 months ago

Kuxe commented 4 months ago

Prerequisites

Steps to reproduce

Passing -RequiredModules directly to New-ModuleManifest works:

$ModuleA = New-Object -TypeName Microsoft.PowerShell.Commands.ModuleSpecification @{
    ModuleName = "MyModule"
    RequiredVersion = [semver]"0.1.2"
}

New-ModuleManifest -Path:"$PSScriptRoot/ModuleB.psd1" -RequiredModules:$ModuleA

Passing -RequiredModules to Update-ModuleManifest fails:

$ModuleA = New-Object -TypeName Microsoft.PowerShell.Commands.ModuleSpecification @{
    ModuleName = "MyModule"
    RequiredVersion = [semver]"0.1.2"
}

New-ModuleManifest -Path:"$PSScriptRoot/ModuleB.psd1"
Update-ModuleManifest -Path:"$PSScriptRoot/ModuleB.psd1" -RequiredModules:$ModuleA

A workaround is to ensure that ModuleA is installed, then Update-ModuleManifest won't fail.

Expected behavior

It's possible to set Required Module via Update-ModuleManifest

Actual behavior

It's not possible to set Required Module via Update-ModuleManifest, it errors with

Cannot update the manifest file 'D:\programming\pwsh/ModuleB.psd1' because the manifest is not valid. Verify that the manifest file is valid, and then try again.'The specified RequiredModules entry 'MyModule' in the module
     | manifest 'D:\programming\pwsh\PSGet_ModuleB.psd1' is invalid. Try again after updating this entry with valid values.'

Error details

PS D:\programming\pwsh> Get-Error

Exception             :
    Type       : System.ArgumentException
    Message    : Cannot update the manifest properly. 'The specified RequiredModules entry 'MyModule' in the module manifest 'D:\programming\pwsh\ModuleB.psd1' is invalid. Try again after updating this entry with valid values.'
    TargetSite :
        Name          : ThrowTerminatingError
        DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Source     : System.Management.Automation
    HResult    : -2147024809
    StackTrace :
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject          : D:\programming\pwsh/ModuleB.psd1
CategoryInfo          : InvalidArgument: (D:\programming\pwsh/ModuleB.psd1:String) [Update-ModuleManifest], ArgumentException
FullyQualifiedErrorId : InvalidModuleManifestFile,Update-ModuleManifest
InvocationInfo        :
    MyCommand        : Update-ModuleManifest
    ScriptLineNumber : 7
    OffsetInLine     : 1
    HistoryId        : 21
    ScriptName       : D:\programming\pwsh\Update-ModuleManifest_bug.ps1
    Line             : Update-ModuleManifest -Path:"$PSScriptRoot/ModuleB.psd1" -RequiredModules:$ModuleA
    Statement        : Update-ModuleManifest -Path:"$PSScriptRoot/ModuleB.psd1" -RequiredModules:$ModuleA
    PositionMessage  : At D:\programming\pwsh\Update-ModuleManifest_bug.ps1:7 char:1
                       + Update-ModuleManifest -Path:"$PSScriptRoot/ModuleB.psd1" -RequiredMod …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : D:\programming\pwsh
    PSCommandPath    : D:\programming\pwsh\Update-ModuleManifest_bug.ps1
    InvocationName   : Update-ModuleManifest
    CommandOrigin    : Internal
ScriptStackTrace      : at ThrowError, C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1: line 7115
                        at Update-ModuleManifest, C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1: line 13336
                        at <ScriptBlock>, D:\programming\pwsh\Update-ModuleManifest_bug.ps1: line 7
                        at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response