McBasic™Get McBasic™ ↗
Build 881
Guided workflow

Build a lifecycle-aware C# component

Compile and package the real LifecycleProbe sample, then observe the runtime boundary from a generated consumer.

Step 1Use a matching development toolchain#

This is a developer-checkout exercise. Open samples/ComponentSdkLifecycle in the McBasic™ source checkout. It references src/McBasic.ComponentSdk and the repository’s centrally selected Avalonia package. Use the repository’s eng/dotnet.sh wrapper rather than assuming a global SDK.

Step 2Read the complete lifecycle implementation#

Open LifecycleProbe.cs. Initialize retains the Lifetime token and tests the logical resource boundary. Activate starts the active phase. Cancellation occurs before Deactivate, then Dispose releases its registration. Read the exact lifecycle contract before modifying the order.

Step 3Compile the component#

From the McBasic™ repository root
./eng/dotnet.sh build samples/ComponentSdkLifecycle/ComponentSdkLifecycle.csproj --configuration Release --output output/lifecycle-tutorial

The assembly is output/lifecycle-tutorial/ComponentSdkLifecycle.dll. Add exported members only through supported SDK attributes. Read the complete C# implementation and project file alongside this lesson.

Step 4Package the declared assembly#

For this unmodified MIT-licensed repository sample, run the exact command below from the repository root. When publishing your own component, choose your own identity, vendor and appropriate license. The assembly-path value is a relative path inside the archive, not a path on the build machine.

Package the local sample for Apple silicon
./eng/mcbasic package-csharp output/lifecycle-tutorial/ComponentSdkLifecycle.dll \
  --output output/lifecycle-tutorial/LifecycleProbe.mbpkg \
  --package-id org.mcbasic.samples.componentlifecycle --version 1.0.0 \
  --minimum-mcbasic-version 0.2.0 --vendor McBasic \
  --description "Lifecycle and resource-boundary teaching component" \
  --assembly-path lib/net10.0/ComponentSdkLifecycle.dll \
  --license-spdx MIT --license-path licenses/LICENSE.txt \
  --license-source samples/ComponentSdkLifecycle/LICENSE.txt --platform osx-arm64

Step 5Admit and run an owned consumer#

These development-mode options are only for the sample you just built, not an unknown third-party package. Runtime-check executes a generated consumer. Observe initialize, activate, cancellation, deactivate and dispose in that order. A static admission pass alone is not runtime evidence.

Separate static and executable gates
./eng/mcbasic package verify output/lifecycle-tutorial/LifecycleProbe.mbpkg \
  --target osx-arm64 --developer-mode true --acknowledge-unsigned true
./eng/mcbasic package runtime-check output/lifecycle-tutorial/LifecycleProbe.mbpkg \
  --target osx-arm64 --developer-mode true --acknowledge-unsigned true

For repeatability and release trust, continue with the package workflow.

Source baseline 20f4bfed6b · Build manifest