Microsoft.WSL.Containers
3.0.3
Prefix Reserved
dotnet add package Microsoft.WSL.Containers --version 3.0.3
NuGet\Install-Package Microsoft.WSL.Containers -Version 3.0.3
<PackageReference Include="Microsoft.WSL.Containers" Version="3.0.3" />
<PackageVersion Include="Microsoft.WSL.Containers" Version="3.0.3" />
<PackageReference Include="Microsoft.WSL.Containers" />
paket add Microsoft.WSL.Containers --version 3.0.3
#r "nuget: Microsoft.WSL.Containers, 3.0.3"
#:package Microsoft.WSL.Containers@3.0.3
#addin nuget:?package=Microsoft.WSL.Containers&version=3.0.3
#tool nuget:?package=Microsoft.WSL.Containers&version=3.0.3
Microsoft.WSL.Containers
The WSL Containers SDK provides APIs for creating and managing Linux containers running inside WSL, and MSBuild/CMake integration for building container images as part of your project.
Supported platforms: x64 and ARM64.
Using the native C/C++ API
MSBuild (via NuGet) and CMake both configure include directories and link libraries automatically when you reference the package. Include the header and link:
#include <wslcsdk.h>
MSBuild: No manual configuration needed — wslcsdk.lib and the include directory are wired up by the imported targets.
CMake:
find_package(Microsoft.WSL.Containers REQUIRED)
target_link_libraries(my_app PRIVATE Microsoft.WSL.Containers::SDK)
The runtime DLL (wslcsdk.dll) is automatically copied to the output directory.
Using the WinRT projection
C++/WinRT
The package includes a WinRT metadata file and automatically:
- Adds
Microsoft.WSL.Containers.winmdas a reference so C++/WinRT generates projection headers - Injects an activation manifest into your binary so
RoGetActivationFactoryresolves the classes towslcsdk.dllwithout COM registration
MSBuild — C++/WinRT (requires the Microsoft.Windows.CppWinRT NuGet package):
#include <winrt/Microsoft.WSL.Containers.h>
auto settings = winrt::Microsoft::WSL::Containers::SessionSettings(L"my-session", L"C:\\path\\to\\storage");
To disable C++/WinRT integration (suppress the winmd reference and manifest injection):
<PropertyGroup>
<WslcEnableCppWinRT>false</WslcEnableCppWinRT>
</PropertyGroup>
C#/WinRT
MSBuild — C# (.NET 8+): The wslcsdkcs.dll projection assembly is referenced automatically.
using Microsoft.WSL.Containers;
var settings = new SessionSettings("my-session", @"C:\path\to\storage");
Building container images
The package integrates the wslc CLI into your build system so container images are built and saved as part of your normal project build, with incremental rebuild support (images rebuild when tracked sources or image build options change).
MSBuild
Add WslcImage items to your project. Each item builds an image and saves it to a .tar archive at build time:
<ItemGroup>
<WslcImage Include="my-server"
Image="ghcr.io/myorg/my-server:latest"
Dockerfile="container/Dockerfile"
Context="container/"
Sources="container/src/**"
TarLocation="$(OutDir)my-server.tar"
BuildArgs="VERSION=1.2.3;COMMIT=abcdef"
Labels="org.opencontainers.image.source=https://example.com/repo" />
</ItemGroup>
<PropertyGroup>
<WslcImageBuildPull>true</WslcImageBuildPull>
<WslcImageBuildNoCache>false</WslcImageBuildNoCache>
</PropertyGroup>
| Metadata | Required | Description |
|---|---|---|
Image |
Yes | Container image reference (:latest appended if no tag) |
Dockerfile |
Yes | Path to the Dockerfile |
Context |
Yes | Build context directory |
Sources |
No | Glob patterns for incremental rebuild tracking (defaults to all files in Context) |
TarLocation |
No | Output path for the saved .tar (defaults to $(OutDir)<name>.tar) |
BuildArgs |
No | Semicolon-separated KEY=VALUE build-time variables (each forwarded as --build-arg) |
Labels |
No | Semicolon-separated KEY=VALUE image labels (each forwarded as --label) |
Optional MSBuild properties:
| Property | Default | Description |
|---|---|---|
WslcCliPath |
wslc |
Path to the wslc CLI executable |
WslcImageBuildPull |
false |
Always attempt to pull newer base images (--pull) |
WslcImageBuildNoCache |
false |
Build images without the layer cache (--no-cache) |
WslcPruneAfterBuild |
false |
Run wslc image prune after each successful build |
WslcTreatPruneFailureAsError |
false |
Fail the build if the post-build prune fails |
CMake
find_package(Microsoft.WSL.Containers REQUIRED)
set(WSLC_IMAGE_BUILD_PULL ON)
set(WSLC_IMAGE_BUILD_NO_CACHE OFF)
wslc_add_image(my-server
IMAGE ghcr.io/myorg/my-server:latest
DOCKERFILE container/Dockerfile
CONTEXT container/
SOURCES container/src/*.cpp container/src/*.h
TAR_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/my-server.tar
BUILD_ARGS VERSION=1.2.3 COMMIT=abcdef
LABELS org.opencontainers.image.source=https://example.com/repo
)
add_dependencies(my_app my-server)
| Argument | Required | Description |
|---|---|---|
<target> |
Yes | Name of the CMake target to create (first positional argument) |
IMAGE |
Yes | Container image reference (:latest appended if no tag) |
DOCKERFILE |
Yes | Path to the Dockerfile |
CONTEXT |
Yes | Build context directory |
SOURCES |
No | Files or glob patterns for incremental rebuild tracking (defaults to all files in CONTEXT) |
TAR_LOCATION |
No | Output path for the saved .tar (defaults to ${CMAKE_CURRENT_BINARY_DIR}/<target>.tar) |
BUILD_ARGS |
No | KEY=VALUE build-time variables (each forwarded as --build-arg) |
LABELS |
No | KEY=VALUE image labels (each forwarded as --label) |
Project-wide CMake variables:
| Variable | Default | Description |
|---|---|---|
WSLC_CLI_PATH |
Found on PATH |
Path to the wslc CLI executable |
WSLC_IMAGE_BUILD_PULL |
OFF |
Always attempt to pull newer base images (--pull) |
WSLC_IMAGE_BUILD_NO_CACHE |
OFF |
Build images without the layer cache (--no-cache) |
WSLC_PRUNE_AFTER_BUILD |
OFF |
Run wslc image prune after each successful build |
WSLC_TREAT_PRUNE_FAILURE_AS_ERROR |
OFF |
Fail the build if the post-build prune fails |
Prerequisites
- WSL — Install with
wsl --install --no-distribution(provides thewslcCLI) - C++/WinRT — Install the Microsoft.Windows.CppWinRT NuGet package for C++/WinRT projection support
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows10.0.19041 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
| native | native is compatible. |
-
net8.0-windows10.0.19041
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Microsoft.WSL.Containers:
| Package | Downloads |
|---|---|
|
Wslc.Testcontainers
Testcontainers-style ephemeral WSL containers for .NET integration tests, built on the Microsoft.WSL.Containers API. |
|
|
Purview.Containers.Wsl
WSL Containers (WSLC) backend for Purview.Containers: run WSLC-native throwaway Linux containers from any .NET 10 project, with automatic Docker fallback. |
GitHub repositories
This package is not used by any popular GitHub repositories.