$PSScriptRoot variable is empty when running an EXE created using paid copy of POSH Tools PRO (4.0)

Issue #3 resolved
Adam Driscoll created an issue

Developing a PowerShell program using PoshTools pro on VS 2017. The program includes a 'PowerShell Form named FormMain.ps1 that references an ICO file on both the Project->Properties->Advanced tab and the Form properties Icon property . Ihen the 'InitializeComponent' function in FormMain.designer.ps1 is called, it's failing at this line of code:

$resources = Invoke-Expression (Get-Content "$PSScriptRoot\FormMain.resources.psd1" -Raw)

Its failing because the $PSScriptRoot variable is empty and so the path that Get-Content ends up using is c:\FormMain.resources.psd1 which, of course, doesn't work because FormMain.resources.psd1 is not in the root of c:, in in the project folder that $PSScriptRoot should contain the path to.

The program runs fine (the $PSScriptRoot variable is set as expected) when run/debugged within VS.

Why is the $PSScriptRoot variable coming up as empty when the executable is run?

Update, 9/19/2018: Uninstalled and reinstalled power shell tools and powershell pro tools - still broken

Comments (5)

  1. Adam Birds

    @adam_driscoll I still see this issue in 4.1.4. Program runs fine when run/debugged through VS. But when ran through EXE, $PSScriptRoot is empty and causes the script to fail.

  2. Log in to comment