Open H4de5-7 opened 3 weeks ago
Hi,
I had success I believe by using an up to date version of the SDK. The SDK should match the version of .NET you are running
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.2" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.3.12" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.19" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.1.0" />
</ItemGroup>
</Project>
I was able to confirm your desired result on net8.0, net7.0 and net6.0. I was unable to run the net5.0 because I don't have the runtime installed.
C:\overhere> dotnet run --configuration Release --framework net8.0
hello123456789hi123456789go123456789
Prerequisites
Steps to reproduce
I used Nuget to download and use the official Microsoft.PowerShell.SDK (7.1.0) and System.Management.Automation (7.1.0). The purpose is to convert a piece of obfuscated code to origianl string. However, this code will truncate part of the execution results. But when I use PowerShell7 and PowerShell5 to call the invoke method in powershell environment
$PowerShell = [powershell]::Create();[void]$PowerShell.AddScript(......);$PowerShell.Invoke()
, I can get the correct results. I suspect there are bugs in the officially provided SDK and Autoumation packages for C#.Expected behavior
Actual behavior
Error details
No response
Environment data
Visuals
No response