Microsoft.PowerShell.Native 6.0.4

Native binaries for PowerShell Core

There is a newer version of this package available.
See the version list below for details.
Install-Package Microsoft.PowerShell.Native -Version 6.0.4
dotnet add package Microsoft.PowerShell.Native --version 6.0.4
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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.

Dependencies

This package has no dependencies.

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

Repository Stars
PowerShell/PowerShell
PowerShell for every system!

Version History

Version Downloads Last updated
7.0.0-preview.4 164 11/11/2019
7.0.0-preview.3 3,393 10/17/2019
7.0.0-preview.2 4,322 9/5/2019
7.0.0-preview.1 9,737 5/24/2019
6.2.0 75,082 3/22/2019
6.2.0-rc.1 3,097 2/25/2019
6.2.0-preview.4 7,339 1/28/2019
6.2.0-preview.3 5,672 12/11/2018
6.2.0-preview.2 3,854 11/16/2018
6.2.0-preview.1 5,070 10/17/2018
6.1.0 69,556 9/25/2018
6.1.0-rc.1 44,431 8/22/2018
6.0.4 26,454 8/11/2018
Show less