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.
<PackageVersion Include="Microsoft.PowerShell.Native" Version="6.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.PowerShell.Native" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version 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.
#:package Microsoft.PowerShell.Native@6.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.PowerShell.Native&version=6.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.PowerShell.Native&version=6.0.4
                    
Install as a Cake Tool

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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
700.0.0-preview.1 242 9/11/2025
7.4.0 4,458,623 11/1/2023
7.4.0-preview.2 116,143 1/10/2023
7.4.0-preview.1 17,145 12/15/2022
7.3.2 2,167,678 1/9/2023
7.3.1 39,273 12/14/2022
7.3.0 445,118 10/27/2022
7.3.0-rc.1 3,731 10/4/2022
7.3.0-preview.1 23,302 2/14/2022
7.2.1 1,328,117 2/2/2023
7.2.0 2,753,774 10/19/2021
7.2.0-preview.2 12,860 5/19/2021
7.2.0-preview.1 7,344 3/13/2021
7.1.0 2,734,770 11/3/2020
7.1.0-rc.2 3,485 10/16/2020
7.0.0 1,747,377 2/12/2020
7.0.0-rc.2 7,825 1/14/2020
7.0.0-rc.1 11,772 12/11/2019
7.0.0-preview.4 3,069 11/11/2019
7.0.0-preview.3 4,265 10/17/2019
7.0.0-preview.2 63,519 9/5/2019
7.0.0-preview.1 17,935 5/24/2019
6.2.0 1,687,624 3/22/2019
6.2.0-rc.1 3,664 2/25/2019
6.2.0-preview.4 10,696 1/28/2019
6.2.0-preview.3 6,320 12/11/2018
6.2.0-preview.2 9,396 11/16/2018
6.2.0-preview.1 7,398 10/17/2018
6.1.0 630,525 9/25/2018
6.1.0-rc.1 141,621 8/22/2018
6.0.4 593,592 8/11/2018