NEWB - Package as Executable?

Trying to Package my first ultra simple PS1 file.

Write-Output "Hello"
Pause

Here is the output:

7/21/2021 12:19:36 PM [NORMAL] - Visual Studio Code v1.58.2 64-bit
7/21/2021 12:19:36 PM [NORMAL] - PowerShell Extension v2021.6.2
7/21/2021 12:19:36 PM [NORMAL] - Operating System: Windows 64-bit
7/21/2021 12:19:36 PM [NORMAL] - Language server starting --
7/21/2021 12:19:36 PM [NORMAL] -     PowerShell executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
7/21/2021 12:19:36 PM [NORMAL] -     PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.6.2' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\modules' -EnableConsoleRepl -StartupBanner '=====> PowerShell Integrated Console v2021.6.2 <=====
' -LogLevel 'Normal' -LogPath 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\logs\1626884376-e7ea78bf-d1cc-4933-8e6f-ff445aab8e381626884369566\EditorServices.log' -SessionDetailsPath 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\sessions\PSES-VSCode-1160-858666' -FeatureFlags @() 
7/21/2021 12:19:36 PM [NORMAL] -     PowerShell Editor Services args: Import-Module 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.6.2' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\modules' -EnableConsoleRepl -StartupBanner '=====> PowerShell Integrated Console v2021.6.2 <=====
' -LogLevel 'Normal' -LogPath 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\logs\1626884376-e7ea78bf-d1cc-4933-8e6f-ff445aab8e381626884369566\EditorServices.log' -SessionDetailsPath 'c:\Users\User\.vscode\extensions\ms-vscode.powershell-2021.6.2\sessions\PSES-VSCode-1160-858666' -FeatureFlags @() 
7/21/2021 12:19:36 PM [NORMAL] - powershell.exe started.
7/21/2021 12:19:36 PM [NORMAL] - Waiting for session file
7/21/2021 12:19:38 PM [NORMAL] - Session file found
7/21/2021 12:19:38 PM [NORMAL] - Registering terminal close callback
7/21/2021 12:19:38 PM [NORMAL] - Registering terminal PID log callback
7/21/2021 12:19:38 PM [NORMAL] - powershell.exe PID: 32444
7/21/2021 12:19:38 PM [NORMAL] - Language server started.
7/21/2021 12:19:38 PM [NORMAL] - {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_mzsi5agw.pap","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_kpb0cz2b.400"}
7/21/2021 12:19:38 PM [NORMAL] - Connecting to language service on pipe \\.\pipe\PSES_mzsi5agw.pap...
7/21/2021 12:19:38 PM [NORMAL] - Language service connected.
7/21/2021 12:19:41 PM [WARNING] - Invalid Version: null

I get no output in the out folder.

Any pointers would be greatly appreciated.

Thanks,
Paul.

Can you please look at the PowerShell Pro Tools output panel? You’ve included the PowerShell extension’s log which won’t have the packager output.

Is this that:

INFO: Checking license

INFO: OutputPath is c:\Users\User\Documents\PowerShell\Test\out

INFO: Bundling c:\Users\User\Documents\PowerShell\Test\Sample PopUp.ps1
INFO: Parsing file c:\Users\User\Documents\PowerShell\Test\Sample PopUp.ps1.

INFO: Bundling XAML
INFO: Failed to locate Import-Xaml

INFO: Packaging C:\Users\User\AppData\Local\Temp\Sample PopUp.ps1

INFO: Creating temp directory: C:\Users\User\AppData\Local\Temp\81ed9fb66feb47a5ba0be72135479654

INFO: Packaging modules...

INFO: Checking dotnet version.
INFO: Checking dotnet version.

INFO: 5.0.302

INFO: 5.0.302

INFO: Creating package project.

INFO: Using .NET Framework version: net462

ERROR: Object reference not set to an instance of an object.

Thanks. That’s helpful. Looking into it.

Thank you so much!

I can reproduce this. To work around it, open the package.psd1 file and add the Resources key like below. I’ll get a fix out for this today.

@{
    Root = 'c:\Users\adamr\Desktop\testfolder\TabbedForm.ps1'
    OutputPath = 'c:\Users\adamr\Desktop\out'
    Package = @{
        Enabled = $true
        Obfuscate = $false
        HideConsoleWindow = $false
        DotNetVersion = 'v4.6.2'
        FileVersion = '1.0.0'
        FileDescription = ''
        ProductName = ''
        ProductVersion = ''
        Copyright = ''
        RequireElevation = $false
        ApplicationIconPath = ''
        PackageType = 'Console'
        Resources = [string[]]@()
    }
    Bundle = @{
        Enabled = $true
        Modules = $true
        # IgnoredModules = @()
    }
}
        

That worked! Did I do something wrong?

That generated 5 files in the out folder. Do I need to have all those files in order to run the .exe file?

Nope. It’s a bug that I’ll get fixed.

You should only need the exe file from that folder.

Here is a follow up - trying to compile a much more complex PS1 script.

Starting PowerShell Pro Tools host from: c:\Users\User\.vscode\extensions\ironmansoftware.powershellprotools-5.29.0\out\windows\PowerShellProTools.Host.exe}
Process started
[7/21/2021 3:18:13 PM] connect

[7/21/2021 3:18:14 PM] Scheduling command for main runspace: $Commands = Get-Command 'Pause' -ErrorAction SilentlyContinue; if ($Commands) { try { [System.Management.Automation.ProxyCommand]::Create((New-Object System.Management.Automation.CommandMetaData $Commands)) } catch { } } else { '' } 

Connecting to PowerShell process 2184
[7/21/2021 3:18:19 PM] Command execution cancelled. Extension is still connecting...

[7/21/2021 3:18:19 PM] Scheduling command for main runspace: $Commands = Get-Command 'Pause' -ErrorAction SilentlyContinue; if ($Commands) { try { [System.Management.Automation.ProxyCommand]::Create((New-Object System.Management.Automation.CommandMetaData $Commands)) } catch { } } else { '' } 

[7/21/2021 3:18:24 PM] Command execution cancelled. Extension is still connecting...

[7/21/2021 3:18:24 PM] Opening a remote runspace.

[7/21/2021 3:18:24 PM] Loading PowerShell Pro Tools module

[7/21/2021 3:18:24 PM] Executing command: [System.Reflection.Assembly]::LoadFrom('c:\Users\User\.vscode\extensions\ironmansoftware.powershellprotools-5.29.0\out\windows\PowerShellProTools.VSCode.dll')

[7/21/2021 3:18:24 PM] Executing command: Import-Module 'c:\Users\User\.vscode\extensions\ironmansoftware.powershellprotools-5.29.0\out\windows\PowerShellProTools.VSCode.dll'

[7/21/2021 3:18:24 PM] Executing command: $Env:PSModulePath += ';c:\Users\User\.vscode\extensions\ironmansoftware.powershellprotools-5.29.0\out\windows\..\Modules'

[7/21/2021 3:18:24 PM] Configuring runspace scheduler.

[7/21/2021 3:18:24 PM] Executing command: 
                Get-Runspace | ForEach-Object {
                    $h = $_.GetType().GetProperty('Host', [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic).GetValue($_)
                    if ($h.Name -eq 'Visual Studio Code Host') 
                    {
                        $_.Id
                    }
                }
            

[7/21/2021 3:18:24 PM] Found VS Code runspace: 4
[7/21/2021 3:18:24 PM] Executing command: 
$RS = Get-Runspace -Id 4
$RS.Events.SubscribeEvent($null, 'PowerShell.OnIdle',  'PowerShell.OnIdle', $null, { 
        try {
        $PSPCommand = [PowerShellProTools.CommandQueue]::GetCommand()
        if ($PSPCommand) 
        { 
            $PSPResults = Invoke-Expression $PSPCommand.Value
            [PowerShellProTools.CommandQueue]::SetResults($PSPResults, $PSPCommand)
        } 
        } catch { [PowerShellProTools.CommandQueue]::SetResults($_.ToString(), $PSPCommand) }
    }, $true, $false)

[7/21/2021 3:18:24 PM] Scheduling command for main runspace: Import-Module 'c:\Users\User\.vscode\extensions\ironmansoftware.powershellprotools-5.29.0\out\windows\PowerShellProTools.VSCode.dll' -Scope Global

Connected to PowerShell process.
[7/21/2021 3:18:25 PM] Scheduling command for main runspace: $Commands = Get-Command 'Pause' -ErrorAction SilentlyContinue; if ($Commands) { try { [System.Management.Automation.ProxyCommand]::Create((New-Object System.Management.Automation.CommandMetaData $Commands)) } catch { } } else { '' } 

[7/21/2021 3:19:00 PM] Scheduling command for main runspace: $Commands = Get-Command 'Pause' -ErrorAction SilentlyContinue; if ($Commands) { try { [System.Management.Automation.ProxyCommand]::Create((New-Object System.Management.Automation.CommandMetaData $Commands)) } catch { } } else { '' } 

[7/21/2021 3:19:32 PM] Scheduling command for main runspace: $Commands = Get-Command 'Pause' -ErrorAction SilentlyContinue; if ($Commands) { try { [System.Management.Automation.ProxyCommand]::Create((New-Object System.Management.Automation.CommandMetaData $Commands)) } catch { } } else { '' } 

[7/21/2021 3:21:46 PM] Scheduling command for main runspace: Get-Variable | Out-PoshToolsVariable -PassThru | ConvertTo-Json -Depth 1 -WarningAction SilentlyContinue

[7/21/2021 3:22:00 PM] Scheduling command for main runspace: Get-Variable | Out-PoshToolsVariable -PassThru | ConvertTo-Json -Depth 1 -WarningAction SilentlyContinue

[7/21/2021 3:22:09 PM] Scheduling command for main runspace: Get-Variable | Out-PoshToolsVariable -PassThru | ConvertTo-Json -Depth 1 -WarningAction SilentlyContinue

INFO: Checking license

INFO: OutputPath is c:\Users\User\Documents\PowerShell\Network Detective Run Windows\out

INFO: OutputPath does not exist. Creating directory.

INFO: Bundling c:\Users\User\Documents\PowerShell\Network Detective Run Windows\Network Detective Run - Windows 3.0 beta.ps1

INFO: Parsing file c:\Users\User\Documents\PowerShell\Network Detective Run Windows\Network Detective Run - Windows 3.0 beta.ps1.

INFO: Bundling XAML

INFO: Failed to locate Import-Xaml

INFO: Packaging C:\Users\User\AppData\Local\Temp\Network Detective Run - Windows 3.0 beta.ps1

INFO: Creating temp directory: C:\Users\User\AppData\Local\Temp\afa1bf9aec9542efa8020a419b6b8b2f

INFO: Packaging modules...

INFO: Checking dotnet version.

INFO: Checking dotnet version.

INFO: 5.0.302


INFO: 5.0.302

INFO: Creating package project.

INFO: Using .NET Framework version: net462

ERROR: Object reference not set to an instance of an object.

Would that be the same fix?

The fix should resolve this. Does the work around not work?

Yes, it does fix the issue. But the exe will not execute without displaying the following:

Can you share your package.psd1 file? I don’t see this issue. If you want, you can also email me the exectuable you created (might need to rename the extension) to adam@ironmansoftware.com

Thanks for sharing the PSD1.

The problem looks like it has to do with a space in the file name (PS1).

For example, I can reproduce this by using the root path: Root = 'c:\Users\adamr\Desktop\testfolder\Tabbed Form.ps1'

That said, this appears to not affect spaces in folder paths: Root = 'c:\Users\adamr\Desktop\test folder\TabbedForm.ps1'

I’ll open an issue for this as well to get it resolved.

Here is a link to the EXE renamed as a text file.