Skip to content

Build: Cache NuGet packages in shared templates - #10

Open
danielchalmers wants to merge 1 commit into
mainfrom
nuget-caching
Open

Build: Cache NuGet packages in shared templates#10
danielchalmers wants to merge 1 commit into
mainfrom
nuget-caching

Conversation

@danielchalmers

@danielchalmers danielchalmers commented Jul 27, 2026

Copy link
Copy Markdown
Member

Neither shared template cached the NuGet global packages folder, so every job in every calling repo did a cold dotnet restore. This adds actions/cache to both.

Changes

template-build-test.yml

  • Workflow-level NUGET_PACKAGES pointing at ${{ github.workspace }}/.nuget/packages.
  • code-quality-check uses actions/cache@v6 (restore + save).
  • build-test uses actions/cache/restore@v6 — restore only. Both jobs run in parallel and restore the same package set, so having a single writer avoids the two of them racing to reserve the same key and emitting Unable to reserve cache warnings. Same split as the .github/actions/build composite in MudBlazor/MudBlazor.

template-deploy-web-app.yml

  • Same cache, keyed on inputs.checkout-repository instead of github.repository. This template can check out a repo other than the caller — MudBlazor/MudBlazor's deploy-trymudblazor.yml deploys from MudBlazor/TryMudBlazor — and keying on the caller would make those two collide on one key with unrelated dependency sets.

Cache key

${{ github.repository }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props', '**/Directory.Build.props', '**/global.json') }}

The prefix matches the convention already in use in MudBlazor/MudBlazor, so this stays consistent if that repo later moves onto the shared template. Two deliberate differences from that repo's version:

  • The hash covers Directory.Packages.props / Directory.Build.props / global.json, not just **/*.csproj. With central package management the versions often don't live in the csproj at all, so a csproj-only hash can go stale. TryMudBlazor has src/Directory.Build.props.
  • restore-keys gives a partial hit when the hash changes, so a single bumped package doesn't force a fully cold restore.

Neither template cached the NuGet global packages folder, so every job in
every calling repo did a cold restore.

- template-build-test: 'code-quality-check' owns the cache; 'build-test'
  restores only, so the two parallel jobs don't race on the same key.
- template-deploy-web-app: keyed on 'checkout-repository' rather than
  'github.repository', since the deploy may check out a different repo.

Key format matches the one already used in MudBlazor/MudBlazor, with the
hash widened to cover Directory.Packages.props, Directory.Build.props and
global.json. restore-keys gives a partial hit when only versions change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant