Repository navigation
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
Reacted by samuel-weber-nc, yoavt-semperis, Charles Miles, RobinGFT and Racci
Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue
Activity
samuel-weber-nc commentedon May 17, 2024
Having exactly the same issue!
kasini3000 commentedon May 22, 2024
dotnet publish MyPowerShellApp -r linux-x64 -c release --self-contained true /p:PublishSingleFile=true
dotnet publish MyPowerShellApp -r linux-x64 -c release --self-contained false /p:PublishSingleFile=true
Having exactly the same issue!
normal without "/p:PublishSingleFile=true"
Environment data
.NET 8
linux-x64
PowerShell.SDK 7.4.2
syryo99 commentedon Jun 3, 2024
Same issue setting:
.NET 8
win-x64
PowerShell.SDK 7.4.2
RobinGFT commentedon Jul 9, 2024
Are there any further updates on this case?
microsoft-github-policy-service commentedon Aug 19, 2024
📣 Hey RobinGFT, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback
RobinGFT commentedon Nov 27, 2024
Issue is still the same, already commented in: #13540 (comment)
DaRacci commentedon Mar 13, 2025
Still encountering this issue.
RobinGFT commentedon Mar 13, 2025
In current stable versions the issue still persists. However, as described in #13540 (comment) if possible you can switch to preview release of the NUGET package, which had solved the problem for my case.
It should be just a matter of time, till the corresponding changes are merged into a stable release.
Drop single-file publish; PS SDK 7.4 can't init in a .NET 8 bundle