Skip to content

ConsoleApp hosting PowerShell fails when published as single file #13540

Closed

Description

@stwehrli

Probably the wrong repo to report this and most likely I did something wrong. I get an exception when I try to create a runspace in a console application published as a single file. Runs fine when published normally.

Steps to reproduce

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.1.0-preview.6" />
  </ItemGroup>
</Project>
using System;
using System.Management.Automation.Runspaces;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var rs = RunspaceFactory.CreateRunspace();
            Console.WriteLine("Hello World!");
        }
    }
}
dotnet publish -r win-x64 --self-contained false /p:PublishSingleFile=true

Expected behavior

Hello World

Actual behavior

Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
 ---> System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at System.Management.Automation.PSVersionInfo..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.PSVersionInfo.get_PSVersion()
   at Microsoft.PowerShell.DefaultHost..ctor(CultureInfo currentCulture, CultureInfo currentUICulture)
   at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()
   at ConsoleApp1.Program.Main(String[] args)

Environment data

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100-preview.8.20417.9
 Commit:    fc62663a35

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100-preview.8.20417.9\

Host (useful for support):
  Version: 5.0.0-preview.8.20407.11
  Commit:  bf456654f9

.NET SDKs installed:
  5.0.100-preview.8.20417.9 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.NETCore.App 5.0.0-preview.8.20407.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.0-preview.8.20411.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Aug 29, 2020
  2. iSazonov commented on Aug 29, 2020

    @iSazonov
    Collaborator

    I tried to compile PowerShell to single file a month ago with the same result.
    I guess the exception comes from follow line:

    string assemblyPath = typeof(PSVersionInfo).Assembly.Location;

    I found 29 such patterns in PowerShell code. And I don't know whether the exception is a .Net bug or we should use another pattern/workaround.

    I think the scenario (single file) has a right to exist and we could support it in next milestone.

    It is a question for PowerShell Committee.

    /cc Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw)

  3. fMichaleczek commented on Aug 30, 2020

    @fMichaleczek
    Contributor

    Ilya (@iSazonov) same problem occurs when trying to publish a Blazor webassembly with SMA. (Not the only one).

  4. stwehrli commented on Aug 31, 2020

    @stwehrli
    Author

    My initial report is not entirely correct. I claimed that a normal publish works. That's not true, at least not on my box. It works fine with a simple build in release mode from Visual Studio 2019 Preview.

    dotnet publish -c release
    

    However, as soon as I publish the solution with a runtime identifier (which is required for single file publish), the binary explodes upon startup. Publishing to win-x64 does not work.

    dotnet publish -c release -r win-x64
    
  5. daxian-dbw commented on Aug 31, 2020

    @daxian-dbw
    Member

    Ilya (@iSazonov) We need to first understand what is the problem before having the committee involved.

  6. iSazonov commented on Sep 1, 2020

    @iSazonov
    Collaborator

    Dongbo Wang (@daxian-dbw) My question is does PowerShell team want to support single file build scenario? If yes we can start to investigate problems in implementation of the scenario.

  7. fMichaleczek commented on Oct 7, 2020

    @fMichaleczek
    Contributor

    API incompatibility :

    API Note
    Assembly.Location Returns an empty string.
    Module.FullyQualifiedName Returns a string with the value of  or throws an exception.
    Module.Name Returns a string with the value of .
    Assembly.GetFile Throws IOException.
    Assembly.GetFiles Throws IOException.
    Assembly.CodeBase Throws PlatformNotSupportedException.
    Assembly.EscapedCodeBase Throws PlatformNotSupportedException.
    AssemblyName.CodeBase Returns null.
    AssemblyName.EscapedCodeBase Returns null.

    Recommendations :

    Action Recommendation
    To access files next to the executable use AppContext.BaseDirectory.
    To find the file name of the executable use the first element of Environment.GetCommandLineArgs().
    To avoid shipping loose files entirely consider using embedded resources.

    Other considerations

    • Single-file doesn't bundle native libraries by default
    • There is an option to set a flag, IncludeNativeLibrariesForSelfExtract, to include native libraries in the single file bundle, but these files will be extracted to a temporary directory in the client machine when the single file application is run
    • Managed C++ components aren't well suited for single-file deployment and we recommend that you write applications in C# or another non-managed C++ language to be single-file compatible.

    Source : Single file deployment and API incompatibility

  8. fMichaleczek commented on Oct 7, 2020

    @fMichaleczek
    Contributor

    Actual behaviour :

    Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
     ---> System.ArgumentException: The path is empty. (Parameter 'path')
       at System.IO.Path.GetFullPath(String path)
       at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
       at System.Management.Automation.PSVersionInfo..cctor()
       --- End of inner exception stack trace ---
       at System.Management.Automation.PSVersionInfo.get_PSVersion()
       at Microsoft.PowerShell.DefaultHost..ctor(CultureInfo currentCulture, CultureInfo currentUICulture)
       at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()
       at ConsoleApp1.Program.Main(String[] args)
    

    string assemblyPath = typeof(PSVersionInfo).Assembly.Location;
    string productVersion = FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion;

    should be replaced by a safer way to get the product info (from the custom attributes of the assembly)

    string productVersion = typeof(PSVersionInfo).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion.Trim();
    
  9. ptupitsyn commented on Nov 30, 2020

    @ptupitsyn

    Any update on this issue? Seems to be a trivial bug to fix.

    Same here, both Windows and Linux. Powershell does not work from single-file apps. Tried the latest preview NuGet as well (7.2.0-preview.1).

    System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
     ---> System.ArgumentException: The path is empty. (Parameter 'path')
       at System.IO.Path.GetFullPath(String path)
       at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
       at System.Management.Automation.PSVersionInfo..cctor()
       --- End of inner exception stack trace ---
       at System.Management.Automation.PSVersionInfo.get_PSVersion()
       at Microsoft.PowerShell.DefaultHost..ctor(CultureInfo currentCulture, CultureInfo currentUICulture)
       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[T](IEnumerable input, IList`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.Invoke[T]()
       at CodeWeTrust.Core.Scripting.PowerShellService.ExecInternal[T](String script, Action`2 logAction, Boolean ignoreStderr, ValueTuple`2[] parameters)
       at CodeWeTrust.Core.Scripting.PowerShellService.Exec[T](String script, Action`2 logAction, Boolean ignoreStderr, ValueTuple`2[] parameters)
       at CodeWeTrust.Core.Cloc.ClocService.ExecuteCloc(String repoPath)
       at CodeWeTrust.Core.Cloc.ClocJob.RunAsync(PipelineContext context)
       at CodeWeTrust.Core.Pipeline.PipelineRunner.RunJobAsync(IPipelineJob job, PipelineContext context, IPipelineProgress progress, IReadOnlyCollection`1 jobsToRun)
    
  10. fMichaleczek commented on Nov 30, 2020

    @fMichaleczek
    Contributor

    Pavel Tupitsyn (@ptupitsyn) no update at this moment. I am working to submit a PR for Wasm. I'm not sure if it will cover everything need for single file app. Do you want to make a contribution ?

  11. iSazonov commented on Dec 1, 2020

    @iSazonov
    Collaborator

    Any update on this issue? Seems to be a trivial bug to fix.

    You could search by Regex "Assembly.*.Location" to find all such patterns we would have to fix.

  12. ptupitsyn commented on Dec 1, 2020

    @ptupitsyn

    Do you want to make a contribution

    Flavien MICHALECZEK (@fMichaleczek) had a closer look at the code - looks like I underestimated the fix, there are multiple places that need updating, including native libraries handling. Not considering a contribution right now, sorry :(

  13. 37 remaining items

  14. RobinGFT commented on May 14, 2024

    @RobinGFT

    Push!
    On year later this issue is still present with .NET 8 and PowerShell.SDK 7.4.2.
    As soon, as I want to build as single file, the appication doesn't run anymore and throws following error at the first execution of a powershell script:

    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()
    

    I fiddled together a custom installer, with a lot of powershell scripts and a lot of dependencies. In normal mode the project is building such a mess on files, that it is hard to find the executable.
    Will Microsoft provide a fix?
    With .NET and PowerShell sharing Microsoft as their mother, I didn't expect to run into such a trouble...

  15. hemanth307 commented on Nov 22, 2024

    @hemanth307

    Push! On year later this issue is still present with .NET 8 and PowerShell.SDK 7.4.2. As soon, as I want to build as single file, the appication doesn't run anymore and throws following error at the first execution of a powershell script:

    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()
    

    I fiddled together a custom installer, with a lot of powershell scripts and a lot of dependencies. In normal mode the project is building such a mess on files, that it is hard to find the executable. Will Microsoft provide a fix? With .NET and PowerShell sharing Microsoft as their mother, I didn't expect to run into such a trouble...

    I am facing the Same issue Sir RobinGFT. Have you found any solution to this issue.

  16. RobinGFT commented on Nov 26, 2024

    @RobinGFT

    Push! On year later this issue is still present with .NET 8 and PowerShell.SDK 7.4.2. As soon, as I want to build as single file, the appication doesn't run anymore and throws following error at the first execution of a powershell script:

    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()
    

    I fiddled together a custom installer, with a lot of powershell scripts and a lot of dependencies. In normal mode the project is building such a mess on files, that it is hard to find the executable. Will Microsoft provide a fix? With .NET and PowerShell sharing Microsoft as their mother, I didn't expect to run into such a trouble...

    I am facing the Same issue Sir RobinGFT. Have you found any solution to this issue.

    Hi hemanth307,
    I'd created a new issue here: #23797 and it seems, that Steve Lee (@SteveL-MSFT) worked on it in #24072 and already merged into master. However I'm not sure, if it has wandered into a officially build (or NuGET) already, I can't find any mentioning in the releases and with the newest NuGET package it is still not working for my case.

  17. fMichaleczek commented on Nov 26, 2024

    @fMichaleczek
    Contributor

    RobinGFT the change is merged in SDK 7.5 Preview release, available on NuGet.org

  18. RobinGFT commented on Nov 27, 2024

    @RobinGFT

    RobinGFT the change is merged in SDK 7.5 Preview release, available on NuGet.org

    Ok, I just had a look and updated to SDK Preview version 7.5.0-rc1 and tested with both .net 8 ad .net 9 , but the issue is still the same:

    ERROR: 2024-11-27T09:29:24.9296259Z - 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](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection1 output, PSInvocationSettings settings)
    at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
    at System.Management.Automation.PowerShell.Invoke()
    at GFT.Installer.CommonInstaller.clsInstallExecutor.runFromPowerShellWithArgs(String cmd, Object[] args) in D:\07_GIT\gitlab.projectserv\Installer\CommonInstaller\clsInstallExecutor.cs:line 50`


    The errors is thrown while executing following code:

    string cmdPermissionCheck = "$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) \r\n" + "if(!$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){ \r\n" + " return -1 \r\n" + "} \r\n" + "return 1";

  19. mr-const commented on Dec 17, 2024

    @mr-const

    I have the very same problem on 7.5.0-rc1 net9.0, but with a little bit different call stack:

    The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
     ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
     ---> System.IO.FileNotFoundException: 
    File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
       at System.Management.Automation.PSObject..cctor()
       at System.Management.Automation.PSObject.get_Properties()
       at System.Management.Automation.SemanticVersion.op_Implicit(SemanticVersion semver)
       at System.Management.Automation.PSVersionInfo..cctor()
       --- End of inner exception stack trace ---
       at System.Management.Automation.PSVersionInfo.get_PSVersion()
       at Microsoft.PowerShell.DefaultHost..ctor(CultureInfo currentCulture, CultureInfo currentUICulture)
       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()
    
  20. nikgoodley-ibboost commented on Jan 3, 2025

    @nikgoodley-ibboost

    I can confirm RobinGFT's observations, even using the 7.5.0-rc.1 seems to have the same issue (though I couldn't entirely rule out some kind of conflict due to various PS versions).

    Having both this and #23797 "closed" (and possibly #24070) makes it unclear whether anyone at MSFT is aware this bug remains or whether another issue needs to be raised to ensure there are eyes on it?

    I am not sure if the change mentioned in #24072 reflects completely the changes mentioned as necessary in this comment.

    I can see in this commit from Steve Lee (@SteveL-MSFT) that the GetApplicationBase has been changed, which is ultimately I think where we see the problem arising, via this line.

    But then I'm not clear what's missing, whether it's not actually reaching the fallback approach of using
    baseDirectory = AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);

    Certainly in my local single file examples, if I had System.Reflection.Assembly.GetExecutingAssembly().Location I would have to change them to AppContext.BaseDirectory in single-file publication and that works. So I'm not sure why this then would still be returning null.

    With the attachment below, in an environment with the 7.5.0-rc.1 SDK and latest dotnet, running the Build.ps1 replicates the issue if this is of any use.
    ps-integration.zip

    Note this fails in the Invoke but it would fail on the PowerShell.Create() call if changed to using var ps = PowerShell.Create(InitialSessionState.CreateDefault());

  21. nikgoodley-ibboost commented on Jan 3, 2025

    @nikgoodley-ibboost

    Hmm, I tried building PowerShell locally and changed my test app's .csproj from

        <ItemGroup>
            <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.0-rc.1" />
            <PackageReference Include="Microsoft.PowerShell.ConsoleHost" Version="7.5.0-rc.1" />
            <PackageReference Include="System.Management.Automation" Version="7.5.0-rc.1" />
        </ItemGroup>
    

    to this (expanding to cover the packages it complained about at compile time)

        <ItemGroup>
            <Reference Include="Microsoft.PowerShell.SDK">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\Microsoft.PowerShell.SDK.dll</HintPath>
            </Reference>
            <Reference Include="Microsoft.PowerShell.ConsoleHost">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\Microsoft.PowerShell.ConsoleHost.dll</HintPath>
            </Reference>
            <Reference Include="Microsoft.PowerShell.Commands.Diagnostics">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\Microsoft.PowerShell.Commands.Diagnostics.dll</HintPath>
            </Reference>
            <Reference Include="Microsoft.PowerShell.Commands.Utility">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\Microsoft.PowerShell.Commands.Utility.dll</HintPath>
            </Reference>
            <Reference Include="Microsoft.PowerShell.Commands.Management">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\Microsoft.PowerShell.Commands.Management.dll</HintPath>
            </Reference>
            <Reference Include="Microsoft.WSMan.Management">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\Microsoft.WSMan.Management.dll</HintPath>
            </Reference>
            <Reference Include="System.Management.Automation">
                <HintPath>D:\dev\src\third-party\PowerShell\src\powershell-win-core\bin\Debug\net9.0\win7-x64\publish\System.Management.Automation.dll</HintPath>
            </Reference>
        </ItemGroup>
    

    And then it did finally seem to work.

    I rarely touch .Net so perhaps this is obvious about the build system but I'm not very clear on why this works locally yet changing the package references wouldn't if the change was incorporated per the earlier comment.

    I tried changing the ItemGroup references to 7.5.0-rc.1, 7.5.0-preview.3 (since when I started the built pwsh this shows PowerShell 7.5.0-preview.3-222-gc0d7fb787f025dffdcc4ea8a05e65004e9e71d66 and pwsh reports its version as 7.5.0-preview.3 though I don't see reference to this string in the repo) and 7.5.0-preview.5 since that appears on https://www.nuget.org/packages/Microsoft.PowerShell.SDK/7.5.0-rc.1#versions-body-tab but none of these worked.

        <ItemGroup>
            <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.0-rc.1" />
            <PackageReference Include="Microsoft.PowerShell.ConsoleHost" Version="7.5.0-rc.1" />
            <PackageReference Include="Microsoft.PowerShell.Commands.Utility" Version="7.5.0-rc.1" />
            <PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="7.5.0-rc.1" />
            <PackageReference Include="Microsoft.PowerShell.Commands.Management" Version="7.5.0-rc.1" />
            <PackageReference Include="Microsoft.WSMan.Management" Version="7.5.0-rc.1" />
            <PackageReference Include="System.Management.Automation" Version="7.5.0-rc.1" />
        </ItemGroup>
    

    I presumed this was my misunderstanding... but then I checked out the packaged source under the latest rc1 release https://github.com/PowerShell/PowerShell/archive/refs/tags/v7.5.0-rc.1.zip and it does not have SteveL-MSFT's change. Not visible in https://github.com/PowerShell/PowerShell/blob/v7.5.0-rc.1/src/System.Management.Automation/engine/Utils.cs#L483

    Dongbo Wang (@daxian-dbw) could there be some problem with the tagging/branching or is there some other reason #24072 wouldn't be incorporated?

  22. fMichaleczek commented on Jan 3, 2025

    @fMichaleczek
    Contributor

    Nik Goodley (@nikgoodley-ibboost) Don't hesitate to read the dotnet runtime design doc and how the msbuild setting impact the compilation. At the end, you will understand that there is no single file without having to rethink the application or with the exclusions it does not look like a single file. I don't think Microsoft will deploy it and if we consider the PAM mode (PowerShell Application Mode) aka the Microsoft.PowerShell.SDK, the developer must go read the dotnet design docs and not PowerShell.
    PowerShell is already slow at startup, adding compression is not good for 100MB.

    https://github.com/dotnet/designs/tree/main/accepted/2020/single-file

    GitHub
    This repo is used for reviewing new .NET designs. Contribute to dotnet/designs development by creating an account on GitHub.
  23. nikgoodley-ibboost commented on Jan 4, 2025

    @nikgoodley-ibboost

    Hi Flavien, thanks for the pointer on the design doc, I hadn't seen it but nevertheless the points it makes were mostly known to me. Understood on general principle; not sure if I'm missing something specifically relating to my comments on the PowerShell build process/resolution of this ticket though?

    The change is already made (and really could be seen as a natural consequence of https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design_3_0.md#api-impact) the question was why #24072 has been merged but the releases don't address the actual issue since you'd said

    RobinGFT the change is merged in SDK 7.5 Preview release, available on NuGet.org

    however, I'm confirming that all of these 7.5 preview versions still have the same issue. The original question and with Robin's comment being unanswered since November was whether the fix from SteveL-MSFT needed more or if it just wasn't in the builds for some reason.

    Seems it's the latter. I've gone through all five 7.5 preview versions and it wasn't in any but I've just seen the one cut three weeks ago for 7.6.0-preview.1 actually says #24072 in the release notes https://github.com/PowerShell/PowerShell/releases/tag/v7.6.0-preview.1 and I see the change affecting this problem in Utils.cs. It just isn't yet in nuget.org (and the master branch doesn't reflect this version), that's the confusing point.

    So the answer is just we have to wait until 7.6 is published or build from source ourselves, I guess.

  24. fMichaleczek commented on Jan 14, 2025

    @fMichaleczek
    Contributor

    I create a script to download/patch/build the source published as single file for Windows with SDK 9.0 Build 101
    https://gist.github.com/fMichaleczek/9ac6d8739149917fa1cf18e3e89ffcae

    {7635837E-E12C-4145-82F9-464B90CA1BE9}

    There is broken features (Get-Help for Core Modules).

    Gist
    Publish PowerShell source code as single filePowerShell Issue 13540 - https://github.com//issues/13540 - build.ps1
  25. RobinGFT commented on Jan 17, 2025

    @RobinGFT

    Version 7.6.0-preview.2 found its way into official NuGet package manager. I upgraded my project via VisualStudio and either build and run where succcesfully. It seems the problem is finally solved 😅😎
    I will do several more tests and write feedback here, if there turn up some more issues.

    At the moment I'm happy 🥳😅

  26. added a commit that references this issue on Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-DevEx-SDKhosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions