Appearance
Chapter 21: Shipping
In Chapter 20: Themes and Accessibility, you gave the game a look that the player can change. The game is now complete, but it only runs from your project folder, on a machine that has the .NET SDK, and only you know that its tests pass.
In this chapter, you publish the game as a build that runs by itself. You also let GitHub build and test it on every push. Finally, you walk through the full requirements list to confirm that every rule has a proof. This is the last chapter, so there is no new game code to write beyond one small clean-up.
| Figure 21-1: The shipping path. Tests pass, the game is published, the published build runs a two second smoke test, and the exit code is 0. This is a drawn illustration, not a screenshot. |
Time: [TODO Simon: time estimate for chapter 21]
In this chapter, you will:
- Put
GameConfiginto its final form. - Publish a self-contained build and run it with the smoke test.
- Check that the host class is still thin.
- Create a GitHub Actions workflow that builds, tests and publishes the game.
- Work through the requirements sign-off and find the proof for every area.
Requirements in this chapter
| ID | Short name |
|---|---|
| PLT-04 | The smoke test exits 0 after the set time |
| PLT-06 | CI builds and tests the game and fails when a check fails |
| PLT-07 | Self-contained publish that runs with no .NET installed |
| NFR-04 | The build has 0 warnings |
| NFR-07 | Every requirement has a test or a checkpoint |
What a published build is
When you run dotnet run, the .NET SDK builds the game and starts it with the .NET runtime that is installed on your machine. A person who only wants to play does not have the SDK or the runtime. They need a folder that holds the game and everything it depends on.
A self-contained publish builds that folder. It copies your compiled game, MonoGame and the .NET runtime into one place, so the game starts on a machine with no .NET installed. The price is size, because the runtime travels with the game. The alternative, a framework-dependent publish, is small but needs the runtime installed.
The runtime is different for each operating system and processor, so you must say which one you want. A runtime identifier, or RID, names the pair. You pass it with -r. The published build runs only on the system its RID names.
| System | Processor | RID |
|---|---|---|
| Windows | 64-bit Intel or AMD | win-x64 |
| Windows | Arm | win-arm64 |
| Linux | 64-bit Intel or AMD | linux-x64 |
| Linux | Arm | linux-arm64 |
| macOS | Intel | osx-x64 |
| macOS | Apple silicon | osx-arm64 |
The smoke test
You added the --smoke-test-seconds option in Chapter 01: The Project and the Host. A smoke test is a cheap check that a build starts and does not fall over at once. With the option, the game opens its window and starts a run with a fixed seed. A short script presses keys to complete one capture, and the game exits with code 0 after the given number of seconds. If no capture completed, it exits with code 3 and prints a message. An invalid value makes it throw an exception, so the exit code is not 0. The script needs about 1.7 seconds, so a value below that fails by design. The smoke run also keeps its profile in your system's temporary folder, so it never changes your own saved profile.
A published build that passes the smoke test has proved the most common shipping faults are absent. The runtime is present, the native MonoGame libraries are found, the window opens and a capture completes, so the gameplay scene, the drawing and the simulation all ran. It cannot show that the picture looks right, which needs your eyes. It has not proved the game plays well, which is what the 163 tests and your own play are for.
Putting GameConfig into its final form
The finished game has one last change to GameConfig.cs. The file loses the comment line above the record, because the record's name and its properties already say what it is. Nothing else changes, so every test result stays the same.
Open Source/Data/GameConfig.cs. Find this line above the GameConfig record:
find Source/Data/GameConfig.cs
csharp
// Every tuning number lives here, so a test can build a small arena with the same code.Delete it. The record and its fifteen properties stay as they were.
In a terminal, from the LastPerimeter folder, run dotnet test. The summary line should report Failed: 0 and Passed: 163. This chapter adds no tests.
Publishing the game
You publish from the project folder. The first command restores the packages for every project in the solution, including the content project that the game project builds. A fresh clone fails to publish without it, with an error that says an assets file is not found.
In a terminal, from the LastPerimeter folder, run the following command:
text
dotnet restore LastPerimeter.slnNow run the publish command. The example is for Windows on a 64-bit Intel or AMD processor. For another system, replace win-x64 with its RID from the table.
text
dotnet publish Platforms/DesktopVK -c Release -r win-x64 --self-containedThe command compiles the game in the Release configuration, which is the optimised build, and copies everything into a publish folder. The last line of its output names the folder. For the Windows example it is:
text
Platforms/DesktopVK/bin/Release/net10.0/win-x64/publishThe pattern is Platforms/DesktopVK/bin/Release/net10.0/<rid>/publish, with your RID in place of <rid>. The folder holds LastPerimeter.exe on Windows, the game's .dll files and the runtime, which makes about 190 files and 82 MB. The name LastPerimeter comes from Resources/Identity.props, the one file where you set the game's name and version.
NOTE
The author ran this publish on Windows 11 with the .NET 10 SDK. The command succeeded in about four seconds and the smoke test below exited with code 0. The Git Bash, Linux and macOS commands follow the same pattern, but they were not run for this chapter, so a Mac in particular needs checking by you.
Running the published build
Open a terminal in the publish folder. In PowerShell, from the LastPerimeter folder, run the following. The | Out-Null makes PowerShell wait for the game to finish, because a Windows game does not hold the terminal on its own, and $LASTEXITCODE would otherwise show an old value.
powershell
cd Platforms/DesktopVK/bin/Release/net10.0/win-x64/publish
./LastPerimeter.exe --smoke-test-seconds 2 | Out-Null
$LASTEXITCODEA window opens for two seconds and closes. The last command prints 0. That is PLT-07 met on your machine.
On Linux or macOS, in bash, from the LastPerimeter folder, run the following. Replace <rid> with your RID. If the shell reports "permission denied", run chmod +x LastPerimeter first.
bash
cd Platforms/DesktopVK/bin/Release/net10.0/<rid>/publish
./LastPerimeter --smoke-test-seconds 2
echo $?The last command prints 0. Any other number means the game did not exit cleanly. A 3 means no capture completed in the time given.
In Git Bash on Windows, from the LastPerimeter folder, run the following. The command runs the Windows build, so it uses the win-x64 folder and the .exe file. Git Bash waits for the game to close, so echo $? shows the real exit code.
bash
cd Platforms/DesktopVK/bin/Release/net10.0/win-x64/publish
./LastPerimeter.exe --smoke-test-seconds 2
echo $?The last command prints 0.
To see the check fail, run the game with an invalid value, such as ./LastPerimeter.exe --smoke-test-seconds abc. The game prints an ArgumentException that says the value is invalid, and the exit code is not 0. This is the behaviour PLT-04 promises, and it is why a CI job can trust the exit code.
TIP
Copy the whole publish folder to another machine with no .NET installed and run it there. This is the real test of a self-contained build. Send the folder as a zip file to share the game.
Checking the host is still thin
Chapter 01: The Project and the Host promised that the MonoGame host owns the MonoGame lifetime and nothing else. Every rule since then went into a service, so the host should still be short. A host that grew to hundreds of lines would mean rules were hiding where no test could reach them.
In PowerShell, from the LastPerimeter folder, run the following:
powershell
(Get-Content Source/Game/LastPerimeterApp.cs).CountIn bash, from the LastPerimeter folder, run the following:
bash
wc -l < Source/Game/LastPerimeterApp.csBoth commands should print 126. A file you typed by hand may differ by a line or two, which is fine. A count near 126 shows the host is still thin. The finished host holds the window, the scene stack and the save hook. The rules live in Source/Systems and Source/Simulation, where the 163 tests reach them.
Building in CI
This section is optional. The game is finished without it, and you can skip to "The requirements sign-off". Do it if you want GitHub to build and test the game for you on every push.
Continuous integration, or CI, runs your build and tests on a clean machine every time you push. It catches the fault that "works on my machine" hides, such as a file that is missing from the repository. GitHub Actions is GitHub's CI service. A workflow is one YAML file that tells it what to run.
The workflow file lives in your repository, not in the game folder. GitHub only reads workflows from the .github/workflows folder at the top of the repository. This section assumes that your repository's top folder contains the LastPerimeter folder. If the top folder is the LastPerimeter folder itself, delete the two defaults blocks and change the artifact path to start with Platforms.
In a terminal, from the top folder of your repository, which is the folder that contains LastPerimeter, run mkdir .github. Then run mkdir .github/workflows. In the .github/workflows folder, create a new file named ci.yml and add the following code. You do not type this into the game, so it is not part of the game's code.
yaml
name: Last Perimeter CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
defaults:
run:
working-directory: LastPerimeter
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
- name: Restore
run: dotnet restore Tests/LastPerimeter.Tests.csproj
- name: Build
run: dotnet build Tests/LastPerimeter.Tests.csproj --configuration Release --no-restore -warnaserror
- name: Test
run: dotnet test Tests/LastPerimeter.Tests.csproj --configuration Release --no-build
publish-windows:
needs: test
runs-on: windows-latest
timeout-minutes: 15
defaults:
run:
working-directory: LastPerimeter
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
- name: Restore
run: dotnet restore LastPerimeter.sln
- name: Build
run: dotnet build Platforms/DesktopVK --configuration Release --no-restore -warnaserror
- name: Publish
run: dotnet publish Platforms/DesktopVK --configuration Release --runtime win-x64 --self-contained
- uses: actions/upload-artifact@v7
with:
name: LastPerimeter-win-x64
path: LastPerimeter/Platforms/DesktopVK/bin/Release/net10.0/win-x64/publishThe key things to note are:
- The
onblock runs the workflow on a push tomain, on a pull request intomain, and by hand from the Actions page. - The
testjob runs on Linux. It restores, builds with-warnaserrorand tests the test project.-warnaserrorturns every warning into an error, so the job fails on a warning. This is how NFR-04 is enforced.--no-restoreand--no-buildstop each step repeating the work of the one before. - The test project is built on its own, because it compiles the shared
Sourcefolder and needs no window. The solution also holds the Windows DirectX project, which a Linux machine cannot build. - The
publish-windowsjob runs on Windows aftertestpasses, which is whatneeds: testsays. It restores the whole solution, builds the game project with-warnaserroras well. NFR-04 then covers the game and not only the tests. It then publishes the game as in the previous section and uploads thepublishfolder as a downloadable artifact. - Each
uses:line names an action and a major version. At the time of writing, the latest majors wereactions/checkout7,actions/setup-dotnet6 andactions/upload-artifact7. The release notes showed no change to the inputs this workflow passes.
The smoke run now proves a capture, as the "The smoke test" section says, but the workflow does not run it in CI. A hosted runner has no display or graphics card. The game opens a Vulkan window, so the smoke test might fail there for reasons that say nothing about your code. Run it on your own machine, as in the previous section.
NOTE
The author ran the three commands of the test job on a clean copy of the chapter 21 project, and the tests reported Passed: 163. The author ran the publish command on Windows. The workflow itself was not run on GitHub for this chapter, so watch the first run of your own copy.
NOTE
First push. Skip this box if your project is already in a GitHub repository. Otherwise, in a browser, create a new empty repository on GitHub. Then, in a terminal, from the top folder of your project, which is the folder that contains LastPerimeter, run git init. Run git add . and then git commit -m "Last Perimeter". Run git branch -M main. Run git remote add origin <url>, replacing <url> with the address GitHub shows for your new repository. Run git push -u origin main.
To start it, commit the new file and push it to your main branch. Open the Actions tab of your repository on GitHub. The run named Last Perimeter CI shows two jobs. A green tick on both is PLT-06 met. To see CI fail, add a stub throw new NotImplementedException(); to a method that a test calls, push, and watch the test job go red. Then undo the change.
The requirements sign-off
The game has 154 requirements, and the requirements list gives each one an acceptance check and a proof. A proof is a named test, or a checkpoint, which is a manual check that a test cannot make because it depends on what the player sees or hears. NFR-07 asks that no requirement has a blank proof. This section is how you confirm it.
Work through it in two parts. First, run every proof test at once. On the requirements list, in the section "Run every proof test at once", run the four combined filter commands from the LastPerimeter folder. Each one should report Failed: 0. A [Theory] reports one pass for each case, so the totals are higher than the number of test names.
Second, work through the table from top to bottom. For a row that names a checkpoint, open the chapter in the Where column and repeat the steps in its "Running the game" section. Tick the row when its proofs have passed and its checkpoints are done.
The sign-off has four commands and 31 checkpoints. [TODO Simon: time estimate for the sign-off]
| Area | Count | Proved by | Where | Done |
|---|---|---|---|---|
| PLT, platform and build | 7 | Parse_UsesSmokeTestArgument_WhenProvided for PLT-04. Checkpoints for PLT-01, 02, 03, 05, 07. CI for PLT-06. | 01, this chapter | [ ] |
| ARN, arena and grid | 8 | ArenaBounds_LeavesMarginAndHudReserves, Constructor_SizesGridFromBoundsAndTileSize, ApplyInsetClaim_ClaimsOnlyTheBorderRing | 03, 14 | [ ] |
| WAL, wall path | 6 | RebuildPlayablePath_MergesCollinearFaces, Contains_UsesTwoPixelTolerance, Rectangle_HasFourNodesWithTwoSegmentsEach | 06 | [ ] |
| INP, input | 5 | PressedEdge_IsTrueForOneFrameOnly, Thumbstick_InsideDeadZone_DoesNotMove, PausePress_OpensPauseAndIsConsumed. Checkpoints for INP-01 and INP-03. | 04, 17 | [ ] |
| MOV, movement | 6 | CalculateNextPosition_ScalesWithDeltaTime, StartLevel_PlacesPlayerOnTopLeftNode, Tick_AppliesRunAndSlowDrawSpeedFactors | 04, 06, 07 | [ ] |
| TRL, trail | 10 | CanAdvance_RefusesClaimedTile, CanCompleteOnPath_RequiresMinimumLength, Cancel_MarksTrailCancelled | 07 | [ ] |
| FUS, fuse | 8 | FuseTriggersAfterDelay_AndReachesPlayer, FusePausesWhenPlayerMoves_AndResumesOnStop, Tick_HoldingBlockedDirection_LetsFuseBurn | 08 | [ ] |
| CAP, capture | 11 | ProcessCompletedTrail_DoesNotChangeTheLiveGrid, Capture_AppendsOrderedCaptureHistory, RejectedLoop_ReturnsPlayerToAnchor. Checkpoints for CAP-09 and CAP-10. | 09, 13 | [ ] |
| ENM, enemies | 12 | CreateRoster_SpreadsEnemiesAcrossTheArena, Retarget_WithPressureTarget_TurnsTowardPlayer, EnclosingCapture_RemovesEliminatedEnemies | 10, 14 | [ ] |
| COL, collision | 3 | PlayerCollision_OnlyCountsWhileDrawing, TrailCollision_IsDetected, Tick_IgnoresHitsDuringGrace | 10, 11 | [ ] |
| LIV, lives and shields | 7 | TryBlockWithShield_SpendsOneChargeInsteadOfALife, LoseLife_OnLastLife_EndsTheRun, SelectRespawnNode_PrefersNodesFarFromEnemies | 11 | [ ] |
| SCO, score | 7 | ScoreClaim_UsesTileCount, CalculateLevelBonus_GrowsWithLevel, RecordRunFinished_KeepsTheHigherScore | 12, 14, 16 | [ ] |
| LVL, levels | 8 | CaptureReachingTarget_ClearsTheLevel, CreateLevel_AddsInsetFromLevelSix, StartLevel_ResetsTheArenaButKeepsTheRun | 14 | [ ] |
| PWR, powerups | 7 | Tick_NeverSpawnsAThirdPowerup, UpdatePowerups_RemovesExpiredPowerups, Apply_EachTypeChangesOnlyItsOwnState | 15 | [ ] |
| RUN, runs and daily | 9 | StartRun_FromLevelSelect_StartsAtChosenLevel, DailySeed_IsTheUtcDayNumber, SameSeedAndInput_GiveTheSameRun. Checkpoint for RUN-09. | 18, 19 | [ ] |
| FE, front end | 9 | MenuList_WrapsAtBothEnds, SceneManager_PushedOverlay_DrawsTheSceneBelow, Tutorial_FinishingLastPage_MarksItCompleted. Checkpoints for FE-01, 08, 09. | 05, 17, 18 | [ ] |
| PRO, profile | 8 | SaveThenLoad_RoundTripsProfileValues, SaveHook_NeverRunsDuringGameplay, RecordLevelCleared_UnlocksNextLevel. Checkpoint for PRO-01. | 16 | [ ] |
| HUD, REN, AUD | 11 | StatusText_MapsEveryEventToALine, Constructor_WithNoAudioDevice_RunsSilentAndPlayDoesNothing. Checkpoints for HUD-01, 02, 04, REN-01 to 04, AUD-01. | 02, 09, 12 | [ ] |
| THM, themes | 5 | Create_EveryPresetFillsEveryRole, ColorblindMode_ReplacesOnlyTheSevenRoles, UiScale_IsClampedToRange. Checkpoints for THM-03 and THM-05. | 20 | [ ] |
| NFR, quality | 7 | SaveHook_NeverRunsDuringGameplay for NFR-02. CI for NFR-04. Code review for NFR-01, 03, 05. The tests of chapters 11 to 18 for NFR-06. This table for NFR-07. | 13, this chapter | [ ] |
The counts add up to 154. Of those, 64 were proved by a test that existed before this course, 59 got their first automated proof here, and 31 rest on a checkpoint or a review. Those 31 are why the "Running the game" sections of every chapter matter. A test cannot see a pixel or hear a tone.
If a filter command reports that no test matches, the filter matched nothing. Check the spelling of the name, and check that you typed the test file in its chapter. If a checkpoint no longer behaves as its chapter says, a later change broke it, and the tests alone would not have told you.
When every row is ticked, NFR-07 is met. Every requirement has a proof, and you have run it.
Running the tests
In a terminal, from the LastPerimeter folder, run dotnet test. The summary line should report Failed: 0 and Passed: 163. This chapter adds no tests, so the count is the same as in Chapter 20.
The tests that matter most for shipping are the ones for PLT-04, which prove the smoke-test option parses. They are Parse_UsesSmokeTestArgument_WhenProvided, Parse_FallsBackToEnvironmentValue_WhenNoArgumentProvided and Parse_ThrowsForMissingArgumentValue.
Running the game
From the LastPerimeter folder, run dotnet run --project Platforms/DesktopVK. Press Enter on the title screen and play a level to the end. The game behaves exactly as it did in Chapter 20. This chapter changed no game behaviour, so the published build should look and play the same. Close the window with its close button.
Then run the published build as described in "Running the published build". Press Enter on its title screen if you run it without the smoke option. It should look the same as the one you ran with dotnet run. The window and the look of the game need your eyes, while the exit code and the test counts need no window.
The next section is optional. It replaces your files with the chapter 21 snapshot.
If you got lost
This section is optional. Use it only when your project no longer builds or the tests no longer match this chapter. It overwrites your Source and Tests folders with the chapter 21 snapshot, so any change of your own in those folders is lost. <course-repo> is the folder where you cloned the course repository.
WARNING
These commands overwrite your own changes in Source and Tests. Copy your project folder elsewhere first if you want to keep it.
In PowerShell, from the LastPerimeter folder, run the following. Replace <course-repo> with the real path first.
powershell
$snapshot = "<course-repo>/DOCUMENTATION/learning_plan_2/snapshots/21-Shipping"
Remove-Item -Recurse -Force Source, Tests
Copy-Item -Recurse "$snapshot/Source" Source
Copy-Item -Recurse "$snapshot/Tests" TestsIn bash, from the LastPerimeter folder, run the following. Replace <course-repo> with the real path first.
bash
snapshot="<course-repo>/DOCUMENTATION/learning_plan_2/snapshots/21-Shipping"
rm -rf Source Tests
cp -r "$snapshot/Source" Source
cp -r "$snapshot/Tests" TestsThen run dotnet test from the LastPerimeter folder and check for Passed: 163.
Common mistakes
dotnet publishfails with "Assets file ... not found". The content project was never restored. From theLastPerimeterfolder, rundotnet restore LastPerimeter.sln, then publish again.- The published game does not start on another machine. The RID does not match that machine. A
win-x64build does not run on Linux or on an Arm processor. Publish again with the right RID. $LASTEXITCODEstill shows an old number after the smoke test. PowerShell did not wait for the game. Add| Out-Nullafter the command, as shown above.- GitHub shows no workflow run. The file is not in
.github/workflowsat the top of the repository, or the folder is insideLastPerimeter. GitHub ignores workflows anywhere else. - The
testjob fails with "project file does not exist". Theworking-directorydoes not match your repository layout. See the note before the workflow listing. - The build fails in CI but passes on your machine.
-warnaserroris on in CI. Read the warning in the log and fix it, because it is a real warning that your editor did not show.
Conclusion
In this chapter, you accomplished the following:
- Put
GameConfiginto its final form and kept all 163 tests green. - Published a self-contained build and ran it with the smoke test, with a runtime identifier for each system.
- Checked that the host is still thin, at about 126 lines.
- Created a GitHub Actions workflow that builds, tests and publishes the game.
- Worked through the requirements sign-off and found a proof for every area.
The tests now prove PLT-04, and the publish and CI steps prove PLT-06 and PLT-07. The sign-off closes NFR-07.
That ends the course. You started with an empty project and one white pixel. You now have a complete arcade game with levels, powerups, menus, saved profiles, upgrades between levels, a daily challenge, themes and accessibility options. It also has 163 tests that prove its rules without a window. More importantly, you have a method: write the contract, write the test, watch it fail, write the code, and let a machine check it every time. Return to the course index to look back over the chapters.
Test Your Knowledge
Why must you give
dotnet publisha runtime identifier for a self-contained build?Answer
The build carries the .NET runtime with it, and the runtime is different for each operating system and processor. The RID says which runtime to copy, and the build runs only on that system.
Why does the
testjob use-warnaserror?Answer
A warning that nobody reads is a warning that grows. Turning warnings into errors makes the job fail the moment one appears, which keeps the build at 0 warnings, as NFR-04 requires.
Why does the CI workflow not run the smoke test?
Answer
The smoke test opens a window with a Vulkan graphics context. A hosted runner has no display or graphics card, so the test might fail for reasons unrelated to your code. A failing check that people learn to ignore is worse than no check.
A requirement in the sign-off says "Checkpoint". Why can no test prove it?
Answer
The result is something the player sees or hears, such as a colour or a tone. A test can compare numbers, but it cannot tell whether a screen looks right. A person makes that check by following the steps in the chapter.
What would a 600 line
LastPerimeterApp.cstell you about the game's rules?Answer
Rules had moved into the host, where tests cannot reach them without a window. The thin-host check exists to catch that drift early.
Extensions
- Add a
publish-linuxjob to the workflow with the RIDlinux-x64, and upload its artifact. Does the job succeed on a Linux runner, and what does that tell you about the game's native libraries? - Change
ApplicationDisplayVersioninResources/Identity.propsto 1.1, publish again, and find where the version appears in the published folder.

