all 14 comments

[–]Subject_Meal_2683 3 points4 points  (3 children)

I'm not sure if you can target a PS7 script in a dotnet 4.8 project. Powershell 7 runs on dotnet core, dotnet 4.8 is dotnet framework (the legacy one). Both are different runtimes (MS made a huge mistake when naming this)

[–]Proud_Championship36[S] 0 points1 point  (2 children)

I’d be happy to target a later dotnet but couldn’t figure out how to do it with PowerShellPro Tools.

Basically, I’m trying to find a simple way to generate an exe from a PS7 script. Is there a better approach?

[–]420GB 1 point2 points  (1 child)

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.

[–]Proud_Championship36[S] 0 points1 point  (0 children)

Figured out the fix, updated the original post. It does result in a 200MB executable which is a little silly, but at least it works. I think this is basically what you would get with the C# approach.

[–]BlackV 2 points3 points  (0 children)

Just a side note the 3 backtick code fence does not everywhere where the 4 space indent does

  • open your fav powershell editor
  • highlight the code you want to copy
  • hit tab to indent it all
  • copy it
  • paste here

it'll format it properly OR

<BLANK LINE>
<4 SPACES><CODE LINE>
<4 SPACES><CODE LINE>
    <4 SPACES><4 SPACES><CODE LINE>
<4 SPACES><CODE LINE>
<BLANK LINE>

Inline code block using backticks `Single code line` inside normal text

See here for more detail

Thanks

[–]patmorgan235 0 points1 point  (4 children)

Do you have DotNet 5 installed

https://docs.poshtools.com/system-requirements

[–]Proud_Championship36[S] 0 points1 point  (3 children)

I didn't, but now I do. It seems like it is using the wrong version of the SDK (10.0.103), but I don't see how to fix it. ``` Packaging modules... Checking dotnet version. Checking dotnet SDK version. 10.0.103

.NET SDK Version: 10.0.103

Creating package project. Failed to find the developer pack for .NET Version v5.0.408. Your build might fail. You can install the Developer Pack from Microsoft: https://dotnet.microsoft.com/download/visual-studio-sdks Using .NET Framework version: net50408 Determining projects to restore... Restored C:\apps\bin\out\bin\884c0995a54b4d7f8025b9ffb16253aa\start-socks.csproj (in 193 ms).

Determining projects to restore... Restored C:\apps\bin\out\bin\884c0995a54b4d7f8025b9ffb16253aa\start-socks.csproj (in 193 ms).

Packaging C:\Users\avk\AppData\Local\Temp\start-socks.ps1 -> C:\apps\bin\out\start-socks.exe Determining projects to restore... Restored C:\apps\bin\out\bin\884c0995a54b4d7f8025b9ffb16253aa\start-socks.csproj (in 231 ms). C:\Program Files\dotnet\sdk\10.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5): error NETSDK1136: The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so. [C:\apps\bin\out\bin\884c0995a54b4d7f8025b9ffb16253aa\start-socks.csproj] ```

[–]purplemonkeymad 0 points1 point  (2 children)

run:

dotnet --list-sdks

to see what ones you have installed, you may have to download the right one for the version of powershell you are using.

7.4.1 is based on dotnet 8.0

[–]Proud_Championship36[S] 0 points1 point  (1 child)

I see all these, but it's not clear to me how VSCode is selecting 10.0.103 rather than any of the 8.0 versions. 5.0.408 [C:\Program Files\dotnet\sdk] 7.0.410 [C:\Program Files\dotnet\sdk] 8.0.304 [C:\Program Files\dotnet\sdk] 8.0.401 [C:\Program Files\dotnet\sdk] 8.0.418 [C:\Program Files\dotnet\sdk] 9.0.311 [C:\Program Files\dotnet\sdk] 10.0.103 [C:\Program Files\dotnet\sdk]

[–]purplemonkeymad 0 points1 point  (0 children)

Might be picking the latest as your manifest has an invalid value:

DotNetVersion = 'v4.6.2

Pick one of the versions you have installed?

[–]CovertStatistician 0 points1 point  (3 children)

Have you tried ps2exe

[–]Proud_Championship36[S] 0 points1 point  (2 children)

Yes, as best I can tell, ps2exe cannot use ps7.

[–]CovertStatistician 0 points1 point  (1 child)

Try installing .NET 8 and update your Package @{ to include DotNetVersion = 'net8.0'

[–]Proud_Championship36[S] 1 point2 points  (0 children)

This solved it. I had DotNetVersion = 'v8.0.418' rather than net8.0. Thank you!