How can I compile a PowerShell 7 script into an executable?

0
5
Asked By TechWhiz42 On

I'm having trouble compiling a PowerShell 7 script into an executable using the PowerShell Pro Tools extension in VSCode. I've installed the 4.6.2 .NET developer kit and runtime framework. My package.psd1 file is set up like this:
```
@{
Root = 'c:appsbinstart-socks.ps1'
OutputPath = 'c:appsbinout'
Package = @{
Enabled = $true
Obfuscate = $false
HideConsoleWindow = $true
PowerShellVersion = '7.4.1'
DotNetVersion = 'v4.6.2'
FileVersion = '1.0.0'
FileDescription = ''
ProductName = ''
ProductVersion = ''
Copyright = ''
RequireElevation = $false
ApplicationIconPath = ''
PackageType = 'Console'
}
Bundle = @{
Enabled = $true
Modules = $true
}
}
```
Every time I try to compile, I get these errors referencing missing namespaces for 'System.Management' and 'Microsoft.PowerShell'. Any advice on what I might be missing?

1 Answer

Answered By DevGuru89 On

It sounds like you're trying to compile a PowerShell 7 script with .NET Framework, but PowerShell 7 runs on .NET Core. You might want to switch to targeting .NET 5 instead since it's more aligned with PowerShell 7. You can change the project settings in PowerShell Pro Tools to target the right framework version for your script.

ScriptNinja16 -

I'd like to target a newer version of .NET but I'm not sure how to do that with PowerShell Pro Tools. Is there an easier way to convert my PS7 script to an executable?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.