-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
I have a .NET 8 Application executing a lot of Powershell commands, but when I build it as a SingleFile it throws an exception.
Issue is already documented in #13540
I also opened an issue in the dotnet repo, which is to find under: dotnet/runtime #102193. There is already a very helpful comment which shows a possible way fixing the issue: Comment
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.2" />
</ItemGroup>
</Project>
using System;
using System.Management.Automation;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
String cmd = "New-Item -Force -Type Directory -Path '%userprofile%\test123'";
PowerShell ps1 = PowerShell.Create().AddScript(cmd);
ps1.Invoke();
}
}
}
dotnet publish -r win-x64 --self-contained false /p:PublishSingleFile=true
Expected behavior
Publish and run successfully.Actual behavior
Publish works, but application doesn' t run. At the first execution of a powershell script, following exception is thrown:
ERROR: 2024-05-14T12:33:51.8318820Z - Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at System.Management.Automation.PSSnapInReader.ReadEnginePSSnapIns()
at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault()
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(PSHost host)
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
Error details
No response
Environment data
- .NET 8
- Win10-x64
- PowerShell.SDK 7.4.2
Visuals
No response
samuel-weber-nc, yoavt-semperis, cmiles, RobinGFT and DaRacci
Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue