r/PowerShell • u/Proud_Championship36 • Mar 06 '26
Question Unable to compile PS7 script into executable using Powershell Pro Tools
I've installed the Powershell Pro Tools extension in the latest VSCode as well as the 4.6.2 .NET developer kit and runtime framework. I have the following package.psd1:
@{
Root = 'c:\apps\bin\start-socks.ps1'
OutputPath = 'c:\apps\bin\out'
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
# IgnoredModules = @()
}
}but always get this error when compiling:
C:\apps\bin\out\bin\36ca0dc2e46544d88b1341681ffbfa26\ConsolePowerShellHost.cs(3,14): error CS0234: The type or namespace name 'Management' does not exist in the namespace 'System' (are you missing an assembly reference?) [C:\apps\bin\out\bin\36ca0dc2e46544d88b1341681ffbfa26\start-socks.csproj]
C:\apps\bin\out\bin\36ca0dc2e46544d88b1341681ffbfa26\ConsolePowerShellHost.cs(5,17): error CS0234: The type or namespace name 'PowerShell' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)[C:\apps\bin\out\bin\36ca0dc2e46544d88b1341681ffbfa26\start-socks.csproj]Can anyone please point me in the right direction?
Update: solved by installing .NET 8.0 SDK and modifying package.psd1 as follows:
@{
Root = 'c:\apps\bin\start-socks.ps1'
OutputPath = 'c:\apps\bin\out'
Package = @{
Enabled = $true
Obfuscate = $false
HideConsoleWindow = $true
PowerShellVersion = '7.4.1'
DotNetVersion = 'net8.0'
DotNetSDKVersion = 'v8.0.418'
FileVersion = '1.0.0'
FileDescription = ''
ProductName = ''
ProductVersion = ''
Copyright = ''
RequireElevation = $false
ApplicationIconPath = ''
PackageType = 'Console'
}
Bundle = @{
Enabled = $true
Modules = $true
# IgnoredModules = @()
}
}
6
Upvotes
View all comments
Show parent comment
2
u/420GB Mar 07 '26
I'm not sure about "better" but you could certainly do it yourself. Create a new C# dotnet 8 project and add the bit of boilerplate code required to initiate an embedded PowerShell runtime, then add and run the script code. Minimal C# knowledge or use of AI required, but it's not hard.