Community.Wsl.Sdk 0.1.0

.NET 5.0 .NET Standard 2.1
There is a newer version of this package available.
See the version list below for details.
dotnet add package Community.Wsl.Sdk --version 0.1.0
NuGet\Install-Package Community.Wsl.Sdk -Version 0.1.0
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="Community.Wsl.Sdk" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Community.Wsl.Sdk --version 0.1.0
#r "nuget: Community.Wsl.Sdk, 0.1.0"
#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 Community.Wsl.Sdk as a Cake Addin
#addin nuget:?package=Community.Wsl.Sdk&version=0.1.0

// Install Community.Wsl.Sdk as a Cake Tool
#tool nuget:?package=Community.Wsl.Sdk&version=0.1.0

Community SDK for Windows Subsystem for Linux

Fork: This repository is based on the awsome work of

This project contains a WSL API wrapper for Windows developers who wants to integrate WSL features into existing Windows applications. You can enumerate, query, executing WSL commands via C# classes.

Supported frameworks

  • .NET Standard 2.1
  • Net. 5
  • Net. 6

Supported Operating Systems

  • Windows 10 x64 16299 or higher
  • Windows 11 x64

How to use

You will need the below items to use the WSL APIs.

  • Add an application manifest which describes your application is compatible with the Windows 10 (GUID: 8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a) and the requestedExecutionLevel tag with asInvoker level.
  • Create instance of ComBasedWslApi
  • Call InitializeSecurityModel() at the top of your application's Main() method.


Due to the limitation of COM security model requirements of WSL APIs, you can not run this SDK within the Visual Studio Test Explorer or LINQPAD.

To circumvent this technical limitation, instruct ComBasedWslApi to use a different set of native methods:

bool isTestEnv = ...;

// decide on implementation at run time
BaseNativeMethods nativeMethods = isTestEnv ? new StubNativeMethods() : new Win32NativeMethods();

// use first parameter of constructor to change the behaviour
var api = new ComBasedWslApi(nativeMethods);

Yet another approach is to use a different implementation of IWslApi altogether. If you already use mocking frameworks & DI, use them to create a test friedly class, for example using FakeItEasy:

var api = A.Fake<IWslApi>();



Use class ComBasedWslApi and an implementation of BaseNativeMethods, if desired.

WSL command execution

There are two implementations, one uses the com based api to execute, the other calls wsl.exe internally. The com based implementation has proven to be quite limited and somehow buggy.

All implementations implement ICommand. Feel free to use your favorite DI or mocking framework to help with testing.

Use class ManagedCommand

Com based

Use class ComCommand

Code Example

Basic usage of wsl api

using Community.Wsl.Sdk.Strategies.Api;

// Create instance
var api = new ComBasedWslApi();

// Place the code Wsl.InitializeSecurityModel() at the top of your application's Main() method.

// Check if wsl is supported
bool isSupported = api.IsWslSupported();

// OR check if wsl is supported and also know why not:
string reason;
bool isSupported = api.IsWslSupported(out reason);

// Enumerate distro list
var distros = api.GetDistroList();

// Query default distro details
var defaultDistro = api.GetDefaultDistro();

Basic command execution

using Community.Wsl.Sdk.Strategies.Api;

// Setup
var api = new ComBasedWslApi();

var distroName = api.GetDefaultDistro()!.Value.DistroName;

// Get command result 
var cmd = new ManagedCommand(
    new string[] { "-n", "test" },
    new CommandExecutionOptions() { StdoutDataProcessingMode = DataProcessingMode.String }


// Wait for the command to finish. Execution is executed asynchronically!
// WaitAndGetResults will fetch the data if instructed or drop it.
var result = cmd.WaitAndGetResults();

// result.Stdout is "test"
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net5.0-windows7.0 is compatible.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows7.0 was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 980 6/12/2022
3.0.0-alpha2 126 6/12/2022
3.0.0-alpha1 112 6/12/2022
2.0.2 475 4/17/2022
2.0.2-alpha3 129 4/17/2022
2.0.2-alpha2 116 4/17/2022
2.0.2-alpha1 118 4/17/2022
2.0.1 387 4/17/2022
0.1.4 286 12/27/2021
0.1.3 222 12/27/2021
0.1.2 229 12/26/2021
0.1.1 226 12/25/2021
0.1.0 230 12/25/2021

## 0.1.0
Enable nuget release