Powershell 7.3 Package not showing GUI

Tool: Visual Studio Code, PSScriptPad, PowerShell 7.3
Version: Extension v2023.3.0

Hello all,

I have a Script wit a dot sourced designer.ps1 file. Basically what is defined in the Design are a few Checkboxes and based on what I select it will install some Software when OK is Clicked.
This works fine when Packaging as exe using Windows Powershell 5.1. Powershell 7.2 also seems to open fine, it shows the GUI and everything works.
But when I Package using Powershell 7.3 and .net7.0 in the Package.psd1 file, it packages into the exe without errors. But when I open the executable, it shows and immediately closes the program within a split second. I sometimes see it Flashing, but sometimes it’s to quick to notice.

In the Windows Event Viewer Log, I see the following records directly after the executable closed.


Applicstrong textation: Installaties_gui_2023.exe
CoreCLR Version: 7.0.423.11508
.NET Version: 7.0.4
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException: The type initializer for ‘System.Management.Automation.PSObject’ threw an exception.
—> System.IO.FileNotFoundException:
File name: ‘Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’
at System.Management.Automation.PSObject…cctor()
— End of inner exception stack trace —
at System.Management.Automation.PSObject.get_Properties()
at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(RunspaceCreationEventArgs args)
at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(RunspaceCreationEventArgs args)
at Microsoft.PowerShell.ConsoleHost.CreateRunspace(RunspaceCreationEventArgs runspaceCreationArgs)
at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName, String configurationFilePath)
at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)
at Microsoft.PowerShell.ConsoleShell.StartImpl(InitialSessionState initialSessionState, String bannerText, String helpText, String args, Boolean issProvided)
at Microsoft.PowerShell.ConsoleShell.Start(String bannerText, String helpText, String args)
at PowerShellToolsPro.Packager.ConsoleHost.Program.Main(String args)


Does somebody have a clue what is going on? Or any suggestions?

Below is a Picture of my Package.psd1 file in case it helps :slight_smile:
image

Thanks in advance.

Jari

I get the same issue, I’ve just been using PS 7.2.7, seems like a bug maybe.

I figured it out about 2 weeks ago but didn’t get the chance to update this Post:

It seems that I need to specify the “Platform” and “RuntimeIdentifier” in the package.psd1 file. In the docs it tells us that the RuntimeIdentifier defaults to “win-x64”, but this seems to be the issue. When I edit the package.psd1 and add RuntimeIdentifier = “win7-x64” or “win10-x64” and also add Platform = “x64”, it starts and works as expected again.
Same story for x86 btw.

This is only needed in Powershell 7.3 and later, in 7.2.x it works without adding those 2 lines in the package.psd1

So if someone is looking for this, here is your answer :slight_smile:

Kind regards,

Jari