Page 1 of 1

Building an exe with Powershell Studio 2019 now causes errors

Posted: Wed Jul 03, 2019 6:44 am
by jeffrey.sikorski@compucom.com
Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.165
OS: Windows 10 Pro (64 Bit)
Build: v10.0.17134.0

I have a script that I have been building into an exe with Powershell Studio 2017
The script runs without errors and the exe that was build runs without errors

When I upgraded to 2019, the exe gets built from the same ps1 without errors BUT when I run the exe it now errors out. Below is the error I get form the command prompt while executing.
  1. Line 5: At line:4 char:1
  2.  
  3. + [CmdletBinding(ConfirmImpact = 'Medium',
  4.  
  5. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6.  
  7. Unexpected attribute 'CmdletBinding'.
  8.  
  9.  
  10.  
  11. At line:6 char:1
  12.  
  13. + param
  14.  
  15. + ~~~~~
  16.  
  17. Unexpected token 'param' in expression or statement.
I have checked the code and do not see any issues and this code works with PSS 2017. Here is the code (lines 1 to 11) where the errors are occurring:
  1. [CmdletBinding(ConfirmImpact = 'Medium',
  2.  
  3.                SupportsShouldProcess = $true)]
  4.  
  5. param
  6.  
  7. (
  8.  
  9.     [Parameter(HelpMessage = 'Path to XML Configuration File')]
  10.  
  11.     [ValidatePattern('.xml$')]
  12.  
  13.     [ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
  14.  
  15.     [string]$Config,
  16.  
  17.     [Parameter(HelpMessage = 'URI to Webservice')]
  18.  
  19.     [string]$Webservice
  20.  
  21. )Codebox]
  22.  
  23.  
  24.  
  25. Any help would be appreciated to get the exe working again on 2019.
  26.  
  27. Thanks

Re: Building an exe with Powershell Studio 2019 now causes errors

Posted: Wed Jul 03, 2019 7:53 am
by Olga_B
Hello,

Could you check what encoding your script has.
Change the encoding to UTF-8-BOM

Re: Building an exe with Powershell Studio 2019 now causes errors

Posted: Wed Jul 03, 2019 8:23 am
by Alexander Riedel
Please indicate also which engine, version, platform etc you package for.

Re: Building an exe with Powershell Studio 2019 now causes errors

Posted: Fri Jul 05, 2019 5:55 am
by jeffrey.sikorski@compucom.com
I use the exe on Windows devices from win7 onward. It is 64bit only. They will have at least PS version 5.

It looks like changing the encoding to UTF-8-BOM fixed the issue.

Re: Building an exe with Powershell Studio 2019 now causes errors

Posted: Mon Jul 08, 2019 5:24 am
by jeffrey.sikorski@compucom.com
jeffrey.sikorski@compucom.com wrote:
Fri Jul 05, 2019 5:55 am
It looks like changing the encoding to UTF-8-BOM fixed the issue.
Actually, it did not fix the issue. I still get the same error. I think I got a false positive by running the wrong exe. But it is a couple of days later and no matter what encoding I choose or build options I keep getting the same error as before.

Re: Building an exe with Powershell Studio 2019 now causes errors

Posted: Mon Jul 08, 2019 6:09 am
by Alexander Riedel
It's caused the code injection to set $PSScriptRoot correctly in packaged code.
It will be fixed in the next service build.
You can leave out the Cmletbinding statement, if possible, and it will package correctly.