Install PowerShell 7.2.0-preview6 or later for the required LoadAssemblyFromNativeMemory
function, then export the PowerShell base installation path:
$Env:PWSH_BASE_PATH="${Env:ProgramFiles}\PowerShell\7-preview"
$Env:PWSH_BASE_PATH="/opt/microsoft/powershell/7-preview"
Build the PowerShell native host program:
mkdir build && cd build
cmake ..
cmake --build .
.\native-host app
mkdir build && cd build
cmake -G "Visual Studio 16 2019" -A x64 ..
cmake --build . --config Release
.\Release\native-host.exe lib
The application native host loads pwsh.exe and launches it with its command-line interface, yet it will not spawn a subprocess: it literally loads the PowerShell application to execute it within the current process. This is useful to avoid leaking sensitive data in command-line parameters.
The library native host loads the PowerShell SDK APIs and calls a few functions for testing.
- https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell
- https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting
- https://github.com/dotnet/runtime/blob/master/docs/design/features/native-hosting.md
- https://github.com/dotnet/runtime/blob/master/docs/design/features/host-components.md
- https://github.com/dotnet/runtime/blob/main/docs/design/features/host-error-codes.md
- https://github.com/dotnet/samples/tree/master/core/hosting
- https://github.com/dotnet/runtime/tree/master/src/coreclr/hosts
- https://github.com/dotnet/runtime/tree/master/src/installer/corehost
- https://github.com/dotnet/runtime/blob/master/docs/design/features/host-probing.md
- dotnet/runtime#35329
- dotnet/runtime#35465
- dotnet/runtime#36990
- dotnet/docs#16646
- https://github.com/sanosdole/nodeclrhost
- dotnet/runtime#46652
- PowerShell/PowerShell#14641
- PowerShell/PowerShell#14652
- https://keithbabinec.com/2020/02/15/how-to-run-powershell-core-scripts-from-net-core-applications/