"Fossies" - the Fresh Open Source Software Archive

Member "PowerShell-7.2.6/docs/host-powershell/README.md" (11 Aug 2022, 2245 Bytes) of package /linux/misc/PowerShell-7.2.6.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.

Host PowerShell Core in .NET Core Applications

PowerShell Core v6.0.1 and Later

The runtime assemblies for Windows, Linux and OSX are now published in NuGet package version 6.*.

Please see the .NET Core Sample Application section for an example that uses PowerShell Core NuGet packages.

.NET Core Sample Application

Note: The .NET Core 2.1 runtime and .NET Core SDK 2.1 or higher is required for the examples below:

You can find the sample application project MyApp in each of the above 2 sample folders. You can quickly test-run it using dotnet run. To build the sample project properly for distribution, run the following command (make sure the required .NET Core SDK is in use):

dotnet publish .\MyApp --configuration release

This builds it for the runtimes specified by the RuntimeIdentifiers property in the .csproj file. Then you can run the MyApp binary from the publish folder and see the results:

PS:> .\MyApp.exe

Evaluating 'Get-Command Write-Output' in PS Core Runspace


Evaluating '([S.M.A.ActionPreference], [S.M.A.AliasAttribute]).FullName' in PS Core Runspace


Special Hosting Scenario For Native Host

There is a special hosting scenario for native hosts, where Trusted Platform Assemblies (TPA) do not include PowerShell assemblies, such as the in-box powershell.exe in Nano Server and the Azure DSC host.

For such hosting scenarios, the native host needs to bootstrap by calling PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext. When using this API, the native host can pass in the path to the directory that contains PowerShell assemblies. A handler will then be registered to the Resolving event of the default load context to deal with the loading of assemblies from that directory.