With the release of PowerShell Core, how can an application choose which version of Powershell (Powershell 5.x or PowerShell Core) is being called when it using hosting automation library (system.management.automation)? Something about the runspace that should be created? or maybe the connection info?
Here's an overview of the PowerShell SDK-related NuGet packages:Adapted from here.
Note: is not recommended for direct use.System.Management.Automation
To create stand-alone applications that host the PowerShell runtime in order to call PowerShell commands in-process:
Use Microsoft.PowerShell.5.ReferenceAssemblies
for .NET Framework (Windows-only) applications using the legacy Windows PowerShell runtime (whose latest and last version is 5.1.x)
Use Microsoft.PowerShell.SDK
for (potentially cross-platform) .NET Core / 5+. applications using the PowerShell (Core) 7 runtime.
Dependencies
section, and consult the first entry; e.g., for package version 7.2.0
the minimum required .NET (Core) runtime is net6.0
.To create assemblies that implement cmdlets / form part of modules for use in PowerShell or to create a PowerShell host:
Use PowerShellStandard.Library
; it is compatible with both Windows PowerShell and PowerShell 7, but note:
As for targeting a specific edition / version via remoting:
Note that it covers remoting from the perspective of using PowerShell cmdlets, not the SDK, though you can always call the cmdlets via the SDK as well.
As Lee Dailey points out in a comment on the question, the edition-specific executable filenames are:
powershell.exe
- Windows PowerShell
pwsh.exe
(Windows) / pwsh
(Unix-like platforms) - PowerShell (Core) 7