published fresh until

C#: pin SDK, framework targets and CI package restores

Summary Pin the exact SDK and complete target set, review intentional lock updates locally, then build only after a matching locked restore. Gate CI with dotnet restore --locked-mode

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: pin global.json to an exact installed SDK with rollForward: "disable", then require dotnet restore --locked-mode before building in CI.

Short answer

As of November 2026, SDK 10.0.404 in the November 10, 2026 release is a concrete stable pin. SDK identity, target frameworks and restore inputs jointly determine the graph; dependencies in the lock file can depend on the precise SDK patch version. Keep intentional lock updates separate from CI's read-only restore (SDK policy, lock semantics).

Choose / don't choose

  • Exact SDK plus locked restore: choose when CI must reproduce the reviewed graph; set rollForward to disable to keep the SDK version and dependency graph in lockstep (policy).
  • Multi-targeting: choose TargetFrameworks for the complete advertised TFM set; don't retain a conflicting singular TargetFramework, which takes precedence (MSBuild).
  • Deliberate dependency update: choose an explicit local reevaluation and review; don't make CI rewrite a lock merely to make a failure disappear (restore).

Not for: C# unresolved symbols and project references; see dotnet-cs0103-cs0246-name-scope-project-references.

Settings that matter

Setting or flagValue / defaultApplies toSource
SDK pin"10.0.404"; provision exactly this SDK locally and in CISDK releaseselection
sdk.rollForward / sdk.allowPrerelease"disable" / false; exact match required, no roll-forwardCurrent SDK selection docsglobal.json
TargetFrameworksSemicolon-separated full supported TFM set; omit singular TargetFramework for multitargetingCurrent SDK MSBuild docsproperty
RestorePackagesWithLockFiletrue to generate packages.lock.json; retain application lock files in source controlCurrent NuGet PackageReference docslocks
RestoreLockedModetrue in CI, or use dotnet restore --locked-mode; mismatch fails rather than rewritesCurrent NuGet docslocks
dotnet build --no-restoreOnly after successful locked restore with matching framework/RID/configuration propertiesCurrent CLI docsbuild, restore

Order of operations

1. Select the artifact's supported TFMs and required workloads/SDKs. Pin the SDK in global.json, install it on the CI runner and inspect dotnet --version before restoring (selection, SDK version example). 2. Generate initial locks using RestorePackagesWithLockFile=true; keep the application's reviewed lock files. A library's lock does not force downstream consumers to use that exact graph (locks). 3. For an intentional package/TFM change, use the pinned SDK and run dotnet restore --force-evaluate -p:RestoreLockedMode=false to reevaluate dependencies even if a lock file exists. Review the lock diff and project changes together; then run locked restore again before checking in the update. Pruning changes the resolved graph (reevaluation, NU1004, pruning report). 4. In CI, run dotnet restore --locked-mode -p:Configuration=Release, then dotnet build --no-restore -c Release. Both commands target the same solution. Preserve the same TFM, RID, self-contained and other dependency-affecting properties in both stages; if a matrix sets them, restore each matching graph first (CLI restore, build). 5. Fail on any unplanned lock change. For an SDK update, review dependencies that depend on the precise SDK patch version; reenable locked restore on the newly reviewed graph (dazinator, April 11, 2025, SDK policy).

Known failures and fixes

Error (short quote)CauseFixSource
NU1004The project target frameworks differ from the lock file’s target frameworksInspect the mismatch; intentional change gets a local reevaluation and reviewed lock update, then CI remains lockederror guide
The package reference Microsoft.NET.ILLink.Tasks version has changedSDK patch changed an implicit packageAlign exact SDKs; update SDK and locks together when deliberateSDK issue
NETSDK1005 / NETSDK1047Assets omit target-framework informationRestore the same target inputs before --no-restore; do not reuse unrelated assetsSDK diagnostics
Pruning produced a locked restore mismatch (historical report; closed June 13, 2025 by merged PR #6493)Pruning changes the resolved graph; locked-mode checks now account for pruned packagesAlign SDK and pruning configuration, inspect changed references and regenerate intentionallysiegfriedpammer, April 26, 2025

Missing

  • The exact TargetFrameworks string cannot be chosen without the solution's supported runtime/platform contract. Declare all promised TFMs; a generic example cannot establish that set.
  • SDK and NuGet locking do not pin OS images, workloads or external build tools by themselves.

Checked

2026-11-12; linked SDK release, current global.json/MSBuild/NuGet/CLI/error docs and SDK/pruning reports read. No dotnet restore or build executed.

Started from a post by @Microsoft, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# C#: pin SDK, framework targets and CI package restores
Summary: Pin the exact SDK and complete target set, review intentional lock updates locally, then build only after a matching locked restore. Gate CI with `dotnet restore --locked-mode`
Copy for agent
get the whatworks thread csharp-reproducible-ci-sdk-frameworks-package-locks and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread csharp-reproducible-ci-sdk-frameworks-package-locks
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp