fresh2dev / AnyBox

The easiest way to develop apps for Windows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Powershell 7 Support

opened this issue · comments

Are there plans to update this module for Powershell 7? Appreciate all the hard work that has been put into this already!

commented

Thank you! I plan for pwsh 7 support someday, but it's not a high priority for me ATM. PRs are welcome, though. =)

Show-AnyBox -Title 'AnyBox Demo' -Message 'Hello world' -Buttons 'Hi' -MinWidth 300

InvalidOperation: H:\Bin\PS\AnyBox\0.4.0\Public\Show-AnyBox.ps1:83:9
Line |
83 | [AnyBox.AnyBox]$AnyBox,
| ~~~~~~~~~~~~~~~
| Unable to find type [AnyBox.AnyBox].

I assume there is no quick work around for this. PS 7.1

Hi there,

I amended the first line of \AnyBox\Types\AnyBox.ps1 from:

Add-Type -ReferencedAssemblies 'System.Management.Automation.dll','System.Drawing.dll','WPF\PresentationFramework.dll','WPF\PresentationCore.dll','WPF\WindowsBase.dll','System.Xaml.dll' -TypeDefinition @"

to:
Add-Type -ReferencedAssemblies 'System.Management.Automation.dll','System.Drawing.dll','PresentationFramework.dll','PresentationCore.dll','WindowsBase.dll','System.Xaml.dll' -TypeDefinition @"

Once I had done this I seemed to be able to successfully run each of the examples detailed within https://clevr.dev/doc/anybox/ within PowerShell 7.0.3. Here's a screenshot of one of the simpler examples:

image

Exact same error after changing Add-Type then Remove-Module AnyBox
PS 7.1 preview 7

Thanks for that RooseBaker. Looks like a reason not to upgrade to 7.1 at the moment. Maybe worthwhile raising this as an issue with the PowerShell 7.1 guys since AnyBox seems to be working OK with 7.0.3 based on the limited testing I've done. I raised a Forms related issue with the PowerShell 7.0 guys a year or so ago and they came up with a workaround very quickly (see PowerShell/PowerShell#11418).

I'm going to start using AnyBox within my existing scripts and will post something here if I hit any issues.

I had a look at getting AnyBox to work with PowerShell 7.1 since I’m about to start testing my scripts against this version. After much playing around I found that amending the first line of \AnyBox\Types\AnyBox.ps1 from:

Add-Type -ReferencedAssemblies 'System.Management.Automation.dll','System.Drawing.dll','WPF\PresentationFramework.dll','WPF\PresentationCore.dll','WPF\WindowsBase.dll','System.Xaml.dll' -TypeDefinition @"

to:

If ($PSVersionTable.PSVersion.ToString() -Like '7.0.') {
$ReferencedAssemblies = 'System.Management.Automation.dll','System.Drawing.dll','PresentationFramework.dll','PresentationCore.dll','WindowsBase.dll','System.Xaml.dll'
} ElseIf ($PSVersionTable.PSVersion.ToString() -Like '7.1.
') {
$PwshPath = Split-Path -Parent (Get-Command -Name pwsh.exe).Path
$ReferencedAssemblies = "$PwshPath\System.Management.Automation.dll","$PwshPath\System.Drawing.dll","$PwshPath\PresentationFramework.dll","$PwshPath\PresentationCore.dll","$PwshPath\WindowsBase.dll","$PwshPath\System.Xaml.dll"
} ElseIf ($PSVersionTable.PSVersion.ToString() -Like '5.1.*') {
$ReferencedAssemblies = 'System.Management.Automation.dll','System.Drawing.dll','WPF\PresentationFramework.dll','WPF\PresentationCore.dll','WPF\WindowsBase.dll','System.Xaml.dll'
} Else {
Throw 'Unsupported PowerShell version.'
}
Add-Type -ReferencedAssemblies $ReferencedAssemblies -TypeDefinition @"

seems to allow Anybox to work against PowerShell versions 5.1, 7.03 and 7.1. I’ve tested quite a few of the examples detailed within https://github.com/dm3ll3n/AnyBox against each of these versions and they operate as expected. I haven’t installed PowerShell 7.2 but I would guess similar code to that used for 7.1 may be required.

I've just installed PowerShell 7.2.2. Amended the first line of \AnyBox\Types\AnyBox.ps1 from:

Add-Type -ReferencedAssemblies 'System.Management.Automation.dll','System.Drawing.dll','WPF\PresentationFramework.dll','WPF\PresentationCore.dll','WPF\WindowsBase.dll','System.Xaml.dll' -TypeDefinition @"

to:

If ($PSVersionTable.PSVersion.ToString() -Like '7.0.') {
$ReferencedAssemblies =
'System.Management.Automation.dll','System.Drawing.dll','PresentationFramework.dll','PresentationCore.dll','WindowsBase.dll','System.Xaml.dll'
} ElseIf ($PSVersionTable.PSVersion.ToString() -Like '7.
') {
$PwshPath = Split-Path -Parent (Get-Command -Name pwsh.exe).Path
$ReferencedAssemblies = "$PwshPath\System.Management.Automation.dll","$PwshPath\System.Drawing.dll","$PwshPath\PresentationFramework.dll","$PwshPath\PresentationCore.dll","$PwshPath\WindowsBase.dll","$PwshPath\System.Xaml.dll"
} ElseIf ($PSVersionTable.PSVersion.ToString() -Like '5.1.*') {
$ReferencedAssemblies = 'System.Management.Automation.dll','System.Drawing.dll','WPF\PresentationFramework.dll','WPF\PresentationCore.dll','WPF\WindowsBase.dll','System.Xaml.dll'
} Else {
Throw 'Unsupported PowerShell version.'
}
Add-Type -ReferencedAssemblies $ReferencedAssemblies -TypeDefinition @"

This seems to allow Anybox to work against PowerShell versions 5.1, 7.03, 7.1 and 7.2. I’ve tested quite a few of the examples detailed within https://github.com/dm3ll3n/AnyBox against each of these versions and they operate as expected.

commented

Big thanks @IanBAdams; I referenced your code when adding v7 support to AnyBox v0.5.0, which is now in the PS Gallery.