InstallHelper: ParseModuleManifest writes error for Manifests with Dynamic script blocks
anamnavi opened this issue · 3 comments
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
Steps to reproduce
Install-PSResource -Name "TestModuleManifestWithIfStatement"
Install-PSResource -Name "ExchangeOnlineManagement"
Both of these will fail because the (Hashtable)data.SafeGetValue() for the ast created from the ModuleManifest fails in Utils.TryParseModuleManifest().
Install-PSResource: Unable to successfully install package 'TestModuleManifestWithIfStatement': 'Cannot generate a PowerShell object for a ScriptBlock evaluating dynamic expressions. Dynamic expression: @{
ModuleVersion = '1.0'
GUID = 'e4da48d8-20df-4d58-bfa6-2e54486fca5b'
Author = 'manikb'
CompanyName = 'Microsoft'
Copyright = '(c) 2015 dagrala. All rights reserved.'
Description = "This is a test module description"
PowerShellVersion = '2.0'
RequiredAssemblies = @()
NestedModules = @()
FunctionsToExport = if($PSEdition -eq 'Desktop') { 'Function1' } else { 'Function2' }
CmdletsToExport = @('Get-Test', 'Set-Test')
VariablesToExport = ''
AliasesToExport = ''
PrivateData = @{
PSData = @{
Tags = @('tag1')
LicenseUri = 'http://this.is.test.license.com'
ProjectUri = 'http://github.com/TestModule'
ReleaseNotes = 'This is our best release so far.'
}
Test = $true
DoNotTest = $false
}
}.'
Expected behavior
It should install the resources
Actual behavior
It writes an error as shown above.
Error details
No response
Environment data
PSGet: 3.0.11
$PSVersionTable:
Name Value
---- -----
PSVersion 7.1.4
PSEdition Core
GitCommitId 7.1.4
OS Microsoft Windows 10.0.22000
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
Besides ExchangeOnlineManagement
, this also affects the following packages:
MicrosoftTeams
PnP.PowerShell
(@pnp/powershell)
I think I am seeing the same thing with my PSScriptTools module. Using Install-PSResource
fails with error Unable to successfully install package 'PSScriptTools': 'Cannot generate a PowerShell object for a ScriptBlock evaluating dynamic expressions.
The module manifest is using the If $PSEdition
logic to dynamically export commands. This has been no problem up until now.
PS 7.2.3 on Windows 11
Resolved with PR #681