Page 1 of 1

Building an exe with Powershell Studio 2019 now causes errors

Posted: Wed Jul 03, 2019 6:44 am
by jscompucom
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. + [CmdletBinding(ConfirmImpact = 'Medium',
  3. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Unexpected attribute 'CmdletBinding'.
  5.  
  6. At line:6 char:1
  7. + param
  8. + ~~~~~
  9. 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:

Code: Select all

[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(HelpMessage = 'Path to XML Configuration File')]
[ValidatePattern('.xml$')]
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
[string]$Config,
[Parameter(HelpMessage = 'URI to Webservice')]
[string]$Webservice
)Codebox]

Any help would be appreciated to get the exe working again on 2019.
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 jscompucom
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 jscompucom
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.