Microsoft.PowerShell.Native 6.0.4

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. 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 (2)

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

Package Downloads
System.Management.Automation The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Runtime for hosting PowerShell

SunamoPS

Working with Powershell 7 - Invoking commands, return outputs etc.

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 356,025 11/1/2023
7.4.0-preview.2 91,695 1/10/2023
7.4.0-preview.1 16,236 12/15/2022
7.3.2 1,842,258 1/9/2023
7.3.1 26,240 12/14/2022
7.3.0 399,045 10/27/2022
7.3.0-rc.1 3,565 10/4/2022
7.3.0-preview.1 22,627 2/14/2022
7.2.1 423,130 2/2/2023
7.2.0 2,223,892 10/19/2021
7.2.0-preview.2 12,337 5/19/2021
7.2.0-preview.1 6,711 3/13/2021
7.1.0 2,207,779 11/3/2020
7.1.0-rc.2 3,149 10/16/2020
7.0.0 1,571,421 2/12/2020
7.0.0-rc.2 7,340 1/14/2020
7.0.0-rc.1 11,322 12/11/2019
7.0.0-preview.4 2,799 11/11/2019
7.0.0-preview.3 3,918 10/17/2019
7.0.0-preview.2 62,099 9/5/2019
7.0.0-preview.1 10,955 5/24/2019
6.2.0 1,331,582 3/22/2019
6.2.0-rc.1 3,497 2/25/2019
6.2.0-preview.4 9,609 1/28/2019
6.2.0-preview.3 6,115 12/11/2018
6.2.0-preview.2 5,257 11/16/2018
6.2.0-preview.1 7,097 10/17/2018
6.1.0 574,916 9/25/2018
6.1.0-rc.1 133,979 8/22/2018
6.0.4 475,553 8/11/2018