Microsoft.PowerShell.Native 6.0.4

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Microsoft.PowerShell.Native --version 6.0.4                
NuGet\Install-Package Microsoft.PowerShell.Native -Version 6.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.PowerShell.Native" Version="6.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.PowerShell.Native --version 6.0.4                
#r "nuget: Microsoft.PowerShell.Native, 6.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Microsoft.PowerShell.Native as a Cake Addin
#addin nuget:?package=Microsoft.PowerShell.Native&version=6.0.4

// Install Microsoft.PowerShell.Native as a Cake Tool
#tool nuget:?package=Microsoft.PowerShell.Native&version=6.0.4                

libpsl-native

This library provides functionality missing from .NET Core via system calls, that are called from from the CorePsPlatform.cs file of PowerShell. The method to do this is a Platform Invoke, which is C#'s Foreign Function Interface to C code (and C++ by way of extern C).

Build

CMake is used to build the project, which results in a libpsl-native.so library on Linux, and libpsl-native.dylib on OS X.

cmake -DCMAKE_BUILD_TYPE=Debug .
make -j

Test

The Google Test framework is used for unit tests.

Use either make test or ctest --verbose for more output.

Notes

Marshalling data from native to managed code is much easier on Linux than it is on Windows. For instance, to return a string, you simply return a copy of it on the heap. Since only one memory allocator is used on Linux, the .NET runtime has no problem later freeing the buffer. Additionally, .NET presumes that the codepage "Ansi" on Linux is always UTF-8. So just marshal the string as UnmanagedType.LPStr.

C# (Managed)

[DllImport("libpsl-native", CharSet = CharSet.Ansi)]
[return: MarshalAs(UnmanagedType.LPStr)]
internal static extern string GetSomeString();

C (Native)

char *GetSomeString()
{
    return strdup("some string");
}

The CoreFX team has an excellent guide for UNIX Interop.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Microsoft.PowerShell.Native:

Package Downloads
System.Management.Automation

Runtime for hosting PowerShell

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Microsoft.PowerShell.Native:

Repository Stars
PowerShell/PowerShell
PowerShell for every system!
Version Downloads Last updated
7.4.0 1,891,104 11/1/2023
7.4.0-preview.2 114,731 1/10/2023
7.4.0-preview.1 16,916 12/15/2022
7.3.2 2,047,797 1/9/2023
7.3.1 31,154 12/14/2022
7.3.0 428,155 10/27/2022
7.3.0-rc.1 3,637 10/4/2022
7.3.0-preview.1 22,920 2/14/2022
7.2.1 900,912 2/2/2023
7.2.0 2,491,399 10/19/2021
7.2.0-preview.2 12,677 5/19/2021
7.2.0-preview.1 7,169 3/13/2021
7.1.0 2,433,980 11/3/2020
7.1.0-rc.2 3,335 10/16/2020
7.0.0 1,668,920 2/12/2020
7.0.0-rc.2 7,640 1/14/2020
7.0.0-rc.1 11,497 12/11/2019
7.0.0-preview.4 2,926 11/11/2019
7.0.0-preview.3 4,097 10/17/2019
7.0.0-preview.2 63,001 9/5/2019
7.0.0-preview.1 13,751 5/24/2019
6.2.0 1,489,449 3/22/2019
6.2.0-rc.1 3,541 2/25/2019
6.2.0-preview.4 10,129 1/28/2019
6.2.0-preview.3 6,174 12/11/2018
6.2.0-preview.2 7,215 11/16/2018
6.2.0-preview.1 7,202 10/17/2018
6.1.0 604,656 9/25/2018
6.1.0-rc.1 139,449 8/22/2018
6.0.4 526,024 8/11/2018