Skip to content

[Repo Assist] [Eng] Add NuGet and npm package caching to CI workflow#4525

Draft
dbrattli wants to merge 2 commits intomainfrom
repo-assist/eng-ci-nuget-npm-caching-2026-04-de479ba7cc732133
Draft

[Repo Assist] [Eng] Add NuGet and npm package caching to CI workflow#4525
dbrattli wants to merge 2 commits intomainfrom
repo-assist/eng-ci-nuget-npm-caching-2026-04-de479ba7cc732133

Conversation

@dbrattli
Copy link
Copy Markdown
Collaborator

Add cache: true + cache-dependency-path to all setup-dotnet steps to
cache ~/.nuget/packages across job runs. Add cache: npm to all
setup-node steps to cache the npm download cache.

This eliminates redundant package downloads on every CI run. The NuGet
cache key is keyed on the hash of all .fsproj files, so it invalidates
automatically when dependencies change.

Closes #4486

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

github-actions bot and others added 2 commits April 11, 2026 09:12
Add cache: true + cache-dependency-path to all setup-dotnet steps to
cache ~/.nuget/packages across job runs. Add cache: npm to all
setup-node steps to cache the npm download cache.

This eliminates redundant package downloads on every CI run. The NuGet
cache key is keyed on the hash of all .fsproj files, so it invalidates
automatically when dependencies change.

Closes #4486

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dbrattli
Copy link
Copy Markdown
Collaborator Author

Note on NuGet caching correctness

The setup-dotnet cache: true feature is designed to work with NuGet lock files (packages.lock.json), not .fsproj files. Using **/*.fsproj as the cache-dependency-path means the cache key won't capture transitive dependency version changes — if a transitive package gets a new version but no .fsproj changes, CI will restore stale cached packages.

For correct caching, the intended setup is:

  1. Add <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> to project files (or Directory.Build.props)
  2. Commit the generated packages.lock.json files
  3. Use cache-dependency-path: "**/packages.lock.json"
  4. Use dotnet restore --locked-mode so restore fails if the lock file is out of date

Reference: https://www.damirscorner.com/blog/posts/20240726-CachingNuGetPackagesInGitHubActions.html

This also has the benefit of reproducible builds beyond just caching. Worth considering whether we want to adopt lock files across the repo before merging this.

@dbrattli dbrattli marked this pull request as draft April 12, 2026 05:36
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.

[Repo Assist] [Eng] Add NuGet and npm caching to CI workflow

1 participant