master
md 52 lines 1.65 KB
Rendered Raw
1 # WSLC-CustomContainer
2
3 A barebones C# console sample that turns text (e.g. a URL) into a **scannable QR
4 code** printed to your terminal — rendered by a tiny Python tool running inside
5 a **custom Linux container**, using the `Microsoft.WSL.Containers` SDK.
6
7 Unlike the other samples (which pull public images), this one ships its own
8 `Containerfile` that is **built automatically as part of the normal build (F5)**
9 via the SDK's `<WslcImage>` MSBuild item — no manual `docker`/`wslc` steps. The
10 app then loads that locally built image from a tar (no registry pull) and runs
11 `qr.py` inside the container.
12
13 ## How the auto-build works
14
15 `WSLCCustomContainer.csproj` declares:
16
17 ```xml
18 <WslcImage Include="customcontainer"
19 Image="customcontainer:latest"
20 Dockerfile="Container\Containerfile"
21 Context="Container"
22 Sources="Container"
23 TarLocation="$(OutDir)customcontainer.tar" />
24 ```
25
26 After `Build`, the package runs `wslc image build` + `wslc image save`,
27 producing `customcontainer.tar` next to the executable. The step is incremental:
28 it only re-runs when files under `Container\` change. (Requires the `wslc` CLI,
29 installed by WSL — `wsl --install --no-distribution`.)
30
31 ## Build
32
33 Requires the .NET 8 SDK. From this folder:
34
35 ```
36 dotnet build -c Debug
37 ```
38
39 ## Run
40
41 ```
42 dotnet run -- "https://aka.ms/wslc"
43 ```
44
45 Pass any text or URL; with no argument it encodes a sample URL. The QR is drawn
46 with Unicode blocks so you can scan it straight from the terminal.
47
48 ## Storage
49
50 Everything lives next to the executable (no absolute paths): `WslcQrStorage\`
51 holds the ephemeral session VHD, and `customcontainer.tar` is the auto-built
52 image.