Compiling PowerShell 7 Scripts into a Executable in VS Code

Thanks Adam.

For Merge-Script, I changed it to “net6.0” and this time worked. Thanks for that. EXE runs fine.

QUESTION: What is the ConfigFile keyword for renaming the exe?

For Visual Studio 2022, I deleted the Release folder, the exe was created, however it does not run either. Even though I am converting the same PS1 script, I found that the exe created using merge-script is 100,004 KB and the exe created with Visual Studio is 98,028KB in size. Should that be the difference while one runs and not the other?

Another thing I noticed is that the ApplicationIconPath parameter is being ignored. It works for Windows Powershell 5.1 but not for .NET Core and PWSH 7.2. The same with the other details: File Description, File Version, Product Name, Product Version, Copyright. They are all ignored.

I have one EXE created a while ago with netcoreapp31 and PWSH 7.1, and the exe details are all included, even the icon.

I’ve opened issues for both of these items (file details and VS not recompiling). The files should be the same size between the two as it should be using the same settings in the compiler. I don’t know why one would be smaller than the other.

Howdy Adam. I think this is because the validation you have on this field says to use ‘net60’. Here is the message:

Merge-Script: Invalid .NET Versions specified. Valid values are: net462, net470, net471, net472, net480, netcoreapp31, net50, net60

By the way, in case this is helpful to anybody else or could help improve how Merge-Scripts works, I could not get my PowerShell 7 script to build until I manually installed Microsoft.PowerShell.SDK via Nuget:

nuget sources Add -Name nuget.org.v3 -Source  https://api.nuget.org/v3/index.json
nuget install Microsoft.PowerShell.SDK

Which resolved this error:

Unable to resolve ‘Microsoft.PowerShell.SDK (>= 7.2.4)’ for ‘net6.0’

1 Like

@mason - Thank you for posting this. Your post should be marked as the solution on this thread.

@adam - Can you advise if there should be an issue raised for this on the tracker?

We should open an issue for this. We have tests running to verify this functionality but there must be a gap in the test case since you shouldn’t have to install it manually.

@adam - Issue #1510 has been raised for this :+1:

1 Like