Community.Wsl.Sdk
2.0.2-alpha1
See the version list below for details.
dotnet add package Community.Wsl.Sdk --version 2.0.2-alpha1
NuGet\Install-Package Community.Wsl.Sdk -Version 2.0.2-alpha1
<PackageReference Include="Community.Wsl.Sdk" Version="2.0.2-alpha1" />
paket add Community.Wsl.Sdk --version 2.0.2-alpha1
#r "nuget: Community.Wsl.Sdk, 2.0.2-alpha1"
// Install Community.Wsl.Sdk as a Cake Addin #addin nuget:?package=Community.Wsl.Sdk&version=2.0.2-alpha1&prerelease // Install Community.Wsl.Sdk as a Cake Tool #tool nuget:?package=Community.Wsl.Sdk&version=2.0.2-alpha1&prerelease
Community SDK for Windows Subsystem for Linux
❗ Fork: This repository is based on the awsome work of wslhub/wsl-sdk-dotnet
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 one default implementations of IWslApi
.
It uses the wsl.exe
executable and (mostly) public information stored in the registry.
❗ Com-Api: WSL has a com-based api that could also used instead. Using com-apis has several disadvantages including security related issues. Using the managed alternative with
wsl.exe
has proven to be more versatile and easier to use.
How to install
This package is available on nuget.org.
You can add a reference using dotnet
:
dotnet add package Community.Wsl.Sdk
API
WSL Api
Class | Description |
---|---|
WslApi |
Get list of installed linux distributions. |
Command |
Execute command in specified linux distribution. |
Code Example
Basic usage of wsl api
using Community.Wsl.Sdk.Strategies.Api;
// Create instance
var api = new WslApi();
// 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 WslApi();
var distroName = api.GetDefaultDistro()!.Value.DistroName;
// Get command result
var cmd = new Command(
distroName,
"echo",
new string[] { "-n", "test" },
new CommandExecutionOptions() { StdoutDataProcessingMode = DataProcessingMode.String }
);
// execute the command and wait for the result (blocks current thread)
var result = cmd.StartAndGetResults();
// OR start and wait asynchronously
// var result = await cmd.StartAndGetResultsAsync();
// result.Stdout is "test"
Unit tests and Mocks
Both WslApi
and Command
implement interfaces, namely IWslApi
and ICommand
. If you already use mocking frameworks & DI, use them to create a test friedly
class, for example using FakeItEasy
:
var api = A.Fake<IWslApi>();
You can also mock specific parts of the implementation by passing custom implementations in the constructor:
/*
Signature of the constructor:
public WslApi(
IRegistry? registry = null,
IIo? io = null,
IEnvironment? environment = null
)
*/
// mock only the IIo logic
var api = new WslApi(
io: A.Fake<IIo>()
);
Migrate from v1 to v2
Breaking changes:
ComBasedWslApi
has been removedComCommand
has been removedManagedWslApi
has been renamed toWslApi
ManagedCommand
has been remamed toCommand
Changed namespace
Community.Wsl.Sdk.Strategies.Command
toCommunity.Wsl.Sdk.Strategies.Commands
Please use the managed api (Managed{WslApi,Command}
). It has the same features and is easier to use.
Product | Versions 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. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows 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. |
-
.NETStandard 2.1
- Microsoft.Win32.Registry (>= 5.0.0)
-
net5.0-windows7.0
- Microsoft.Win32.Registry (>= 5.0.0)
-
net6.0-windows7.0
- Microsoft.Win32.Registry (>= 5.0.0)
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.1.0 | 136 | 8/17/2024 |
3.1.0-alpha1 | 108 | 8/17/2024 |
3.0.0 | 1,215 | 6/12/2022 |
3.0.0-alpha2 | 203 | 6/12/2022 |
3.0.0-alpha1 | 183 | 6/12/2022 |
2.0.2 | 551 | 4/17/2022 |
2.0.2-alpha3 | 200 | 4/17/2022 |
2.0.2-alpha2 | 183 | 4/17/2022 |
2.0.2-alpha1 | 193 | 4/17/2022 |
2.0.1 | 451 | 4/17/2022 |
0.1.4 | 356 | 12/27/2021 |
0.1.3 | 284 | 12/27/2021 |
0.1.2 | 287 | 12/26/2021 |
0.1.1 | 288 | 12/25/2021 |
0.1.0 | 278 | 12/25/2021 |
(grafted, HEAD, tag: v2.0.2-alpha1) --skip-duplicate