Community.Wsl.Sdk 0.1.2

.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.2
NuGet\Install-Package Community.Wsl.Sdk -Version 0.1.2
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.2" />
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.2
#r "nuget: Community.Wsl.Sdk, 0.1.2"
#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.2

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

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

There are two different implementations of IWslApi:

  • A COM-based one that has specific requirements and requires special setup, too
  • An alternative implementation that uses wsl.exe and (mostly) public information stored in the registry.

It's recommended to use the alternative because it's more versatile and easier to use.

How to install

This package is available on
You can add a reference using dotnet / nuget:

dotnet add package Community.Wsl.Sdk



Classes Description
ManagedWslApi Get list of installed linux distributions.
ManagedCommand Execute command in specified linux distribution.
ComCommand Get list of installed linux distributions.
ComBasedWslApi Execute command in specified linux distribution.

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 buggy.

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

Code Example

Basic usage of wsl api

using Community.Wsl.Sdk.Strategies.Api;

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

// When class ComBasedWslApi is used
// Place the code Wsl.InitializeSecurityModel() at the top of your application's Main() method.
// api.InitializeSecurity();

// 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 ManagedWslApi();

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"

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>();
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 989 6/12/2022
3.0.0-alpha2 127 6/12/2022
3.0.0-alpha1 113 6/12/2022
2.0.2 475 4/17/2022
2.0.2-alpha3 130 4/17/2022
2.0.2-alpha2 117 4/17/2022
2.0.2-alpha1 118 4/17/2022
2.0.1 388 4/17/2022
0.1.4 287 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 231 12/25/2021

## 0.1.2
Fix ManagedCommand. (#1)