Skip to content

CI: cache NuGet packages in the test legs and the Pack job #249

Open

Description

@CaffeinatedCoder

Why

No job in dotnet.yml caches NuGet packages, so every test leg downloads the whole dependency graph again. Over 50 runs between 29 and 31 Oct, the Restore step's median was 51 s on Windows, 13 s on Linux and 14 s on macOS (8 runs). The Pack job's Build restores the same way. setup-dotnet's built-in cache: true needs packages.lock.json files, which this repository does not have.

Proposal

  • An actions/cache step (pinned to a SHA, with its # vX.Y.Z comment, like the other actions) after Setup .NET in the test legs and the Pack job. It caches ~/.nuget/packages, keyed on the runner OS and hashFiles('Directory.Packages.props', '**/*.csproj', '**/Directory.Build.props', 'global.json', '.config/dotnet-tools.json'). Its restore-keys are the OS prefix, so a changed pin restores most packages and downloads the rest.
  • The smoke test is untouched: it sets its own NUGET_PACKAGES under its work folder (tools/ConsumerSmokeTest/Program.cs), and that private cache is the point of its two modes. The Consumer job gets no cache.
  • No cache in a run that publishes. dotnet.yml gets a workflow_call input publishing (boolean, default false). release.yml's ci job passes publishing: true, and every cache step carries if: ${{ !inputs.publishing }} (under any other event the input is unset, so the cache is used). After Release: publish the packages CI packed instead of building them again, and check the tag before CI #247, that run's Pack job builds the packages nuget.org receives. They are then restored from nuget.org, so NuGet checks every package's signature as it extracts it. Nothing comes from an Actions cache, whose contents skipped that check and which any run on the default branch can write. This covers the tag push and a non-dry-run dispatch of release.yml from a branch, which a ref check would miss.
  • Fresh means two different things here. The smoke consumers restore into their own empty folder in every run, cached or not, which is what their two modes test. The publishing run restores everything from nuget.org, which is what the packages it publishes are built from. The test legs of that run go without a cache too, so one rule covers the whole run.
  • ReleaseWiringTests hold both halves: release.yml's ci passes publishing: true, and every actions/cache step in dotnet.yml carries the condition. Each is shown failing on a seeded omission.

Done when

The Restore step is measured before and after on each leg, in this issue. A cache hit and a miss (after a change to Directory.Packages.props) both pass. The smoke test's two modes still restore from their own folders. A dry-run dispatch of release.yml restores no cache in any job.

Activity

  1. added this to the 2.4.0 milestone on Oct 31, 2026
  2. added
    chore
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    chore

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions