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.
#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
7.4.0 3,855,862 11/1/2023
7.4.0-preview.2 115,994 1/10/2023
7.4.0-preview.1 17,076 12/15/2022
7.3.2 2,137,699 1/9/2023
7.3.1 37,647 12/14/2022
7.3.0 444,078 10/27/2022
7.3.0-rc.1 3,693 10/4/2022
7.3.0-preview.1 23,215 2/14/2022
7.2.1 1,240,536 2/2/2023
7.2.0 2,696,612 10/19/2021
7.2.0-preview.2 12,816 5/19/2021
7.2.0-preview.1 7,310 3/13/2021
7.1.0 2,662,689 11/3/2020
7.1.0-rc.2 3,439 10/16/2020
7.0.0 1,733,408 2/12/2020
7.0.0-rc.2 7,785 1/14/2020
7.0.0-rc.1 11,644 12/11/2019
7.0.0-preview.4 3,027 11/11/2019
7.0.0-preview.3 4,225 10/17/2019
7.0.0-preview.2 63,437 9/5/2019
7.0.0-preview.1 17,802 5/24/2019
6.2.0 1,636,054 3/22/2019
6.2.0-rc.1 3,624 2/25/2019
6.2.0-preview.4 10,595 1/28/2019
6.2.0-preview.3 6,275 12/11/2018
6.2.0-preview.2 8,964 11/16/2018
6.2.0-preview.1 7,338 10/17/2018
6.1.0 626,480 9/25/2018
6.1.0-rc.1 141,172 8/22/2018
6.0.4 577,016 8/11/2018