Skip to content

CI & automation

Targets net10.0Last reviewed 2026-10-09 freshSources andrew-lock dotnet-blog house:simon-mckenna meziantou ms-learn

Treat supply-chain security as a requirement. Agents now write and run much of the code in a pipeline, so nobody reviews each step by hand.

Opinions

  • Pin GitHub Actions to commit SHAs, not mutable tags. A tag can move without warning, and a SHA can't. Enforce pinning in every repository, and script it when you have many. (Meziantou: SHA pinning)
  • Never interpolate user input into a workflow script. Pass it in an environment variable, and parse it in the script. Script injection is the most common GitHub Actions vulnerability. (Meziantou: Safely passing extra arguments)
  • Pin the SDK and every package in CI. global.json sets the SDK, and lock files or Central Package Management set the packages. A CI run must never pick up a version the repository didn't choose. (Microsoft Learn: global.json overview, Meziantou: Faster and Safer NuGet restore using Source Mapping and Lock files)
  • If you restore from more than one feed, use package source mapping. Without it, "If you have a package published on an internal feed... with the same name as a public package, the public package can be used instead". (Meziantou: NuGet Packages: security risks and best practices)

    • Map every package to a source in one nuget.config at the repository root.
    • Start its sources with <clear/>, so no inherited source survives.
    • Leave no package pattern unmapped.

    Mapping filters restore and nothing else: dotnet package add still reaches any configured source. (Microsoft Learn: Package Source Mapping) A repository that restores only from nuget.org gains little, because nuget.org never replaces a published version.

  • Treat vulnerability warnings as build errors everywhere. NuGet Audit runs during restore, and "NuGetAuditMode defaults to all when a project targets net10.0 or higher", so it checks the whole graph. (Microsoft Learn: Auditing package dependencies for security vulnerabilities) TreatWarningsAsErrors, which templates/Directory.Build.props sets, turns NU1901 to NU1904 into errors. Restore then fails on the day an advisory lands, even if nobody changed the graph. That's intended: triaging the advisory is the first step in servicing the branch.

    .NET 10 prunes platform-provided packages from the graph before the audit, so the report is shorter: "Projects with these defaults have 70% fewer transitive vulnerability reports compared to projects using the previous defaults". (Kolev: NuGet Package Pruning: Cleaner Dependencies and Actionable Vulnerability Reports)

  • Restrict what a package can run, not only which version restores. A PackageReference can bring MSBuild props and targets, analyzers, and source generators. All of them run during restore, design-time build, and compile. A version pin decides which code you get, not whether it runs. List only the asset types a package needs:

    • Use IncludeAssets="compile;runtime" for a library you only call.
    • Use PrivateAssets="all" on build-only tooling, so it never flows to your consumers.
    • Under Central Package Management, set both on the PackageReference, never the PackageVersion. A PackageVersion holds a package ID and version. For tooling that every project uses, add a GlobalPackageReference to Directory.Packages.props instead, which gets PrivateAssets="All" implicitly. NuGet 7.9 fixed a bug in which dotnet add package wrote PrivateAssets to the PackageVersion item. (Microsoft Learn: Central Package Management, Microsoft Learn: NuGet 7.9 Release Notes)

    Packages that are mostly build logic need these loosened. Re-test after you tighten them. (Meziantou: Limit what NuGet packages can do in your project)

House opinion · Simon McKenna

House: Treat warnings as errors on every machine, not only in CI. A warning that fails CI but not your local build reaches a pull request before anyone sees it. templates/Directory.Build.props sets TreatWarningsAsErrors unconditionally, so warnings fail the build locally too. Every suppression, whether #pragma warning disable, [SuppressMessage], or a <NoWarn> entry, needs an inline comment that says why. Revert a suppression that has none.

Pipeline shape

Run four stages in order: restore, build, test, and publish. Each stage skips the work of the one before it. Pass --no-restore to build, and --no-build to test and publish. Each stage then uses the previous stage's output instead of rebuilding with different flags.

Pass the same --configuration to every stage. dotnet publish defaults to Release for current target frameworks, but dotnet build and dotnet test default to Debug. A --no-build stage with a different configuration looks for output that doesn't exist. The example uses GitHub Actions, but the stages work on any CI platform. (Microsoft Learn: dotnet publish, Microsoft Learn: dotnet test)

  1. Restore. If the repository commits packages.lock.json (RestorePackagesWithLockFile=true), pass --locked-mode, so a stale lock file fails the build. Without a lock file, the flag fails every restore with NU1004. The templates pin packages with Central Package Management in templates/Directory.Packages.props, and templates/Directory.Build.props turns lock files off, so the example restores without it.
  2. Build. Build once, in Release, with -warnaserror. Keep the switch even though the template sets TreatWarningsAsErrors. The property covers compiler and analyzer diagnostics. The switch also fails on MSBuild warnings, such as MSB3277 assembly version conflicts.
  3. Test. Run dotnet test on Microsoft.Testing.Platform (MTP). MTP needs the test.runner opt-in in global.json, as testing.md describes. Without it, the SDK uses VSTest, which fails on .NET 10 before --no-build takes effect.
    • Upload TRX and coverage files as build artifacts, so you can diagnose a failure without a rerun.
    • Under xunit.v3, write TRX with --report-xunit-trx and --results-directory, as in the example. Upload the results even when the step fails, because the failed run is the one you need them for.
    • MTP rejects VSTest's --logger trx. For details, see testing.md. (Microsoft Learn: What's new in .NET 10: SDK)
  4. Publish or pack. Pass --no-build, and upload the output as the one artifact that deploy and release consume. Never rebuild for deployment.
# Least privilege: unless the repository says otherwise, the default token can
# write to contents, and a build job doesn't need to.
permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6
        with:
          global-json-file: global.json
      - run: dotnet restore
      - run: dotnet build --no-restore --configuration Release -warnaserror
      - run: dotnet test --no-build --configuration Release --report-xunit-trx --results-directory artifacts/test-results
      - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
        if: ${{ !cancelled() }}
        with:
          name: test-results
          path: artifacts/test-results
      - run: dotnet publish --no-build --configuration Release
      - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
        with:
          name: app
          path: artifacts/publish

This repository runs the checkout and setup-dotnet pins. The upload-artifact pin is only an example. When you copy the workflow, resolve every SHA against the current release, and check the major version. A pinned SHA never reports that it's out of date, so pair SHA pinning with a dependency bot.

Artifact signing

Spend your signing effort on provenance and credentials, not on author signing. For NuGet packages:

Review by 2026-11-01. Every nuget.org API key created before 2026-08-17 expires on 2026-11-01. After that date, every key is on the 30-day cap, and you can drop this note.

To protect consumers, pin: locked restore, a pinned SDK, and SHA-pinned actions.

Don't add a signer allow list (signatureValidationMode set to require, with trustedSigners in nuget.config) unless you can maintain it. Each certificate rotation fails installs with NU3034 until you add the new SHA-256 fingerprint beside the old ones. Microsoft rotated its author-signing certificate from 2026-09-23. (.NET Blog: Microsoft is updating its author-signing certificate starting September 23, 2026)

Dependency updates

Use Renovate, with one shared configuration preset across every repository. It updates everything a .NET repository pins: NuGet packages (grouped, with lock file maintenance), the SDK in global.json, .nuspec dependencies, and action SHAs. (Meziantou: Sharing the Renovate configuration across multiple projects, Meziantou: Update dependencies in nuspec with Renovate) Dependabot lost because it can't share configuration across repositories, so each repository's policy drifts.

Merge updates only through the pipeline above. An update that skips locked restore and tests is a supply-chain risk.

House opinion · Simon McKenna

House: Leave the bot's dependency dashboard issue open. Renovate manages it, and closing it doesn't opt out: the next run re-creates it under a new number and notifies everyone again.

  • It's the only list of pending updates. Updates held back by prConcurrentLimit, or blocked by a failing branch, appear nowhere else. Its checkboxes trigger an off-schedule run without a configuration change.
  • It's where you approve gated updates. With dependencyDashboardApproval set, Renovate opens a pull request only after you tick the update's box on the dashboard.
  • dependencyDashboardAutoclose lost. It closes the issue whenever nothing is pending. A new issue every cycle costs more attention than one that stays open, and the closed issue hides a growing backlog.
  • If a stale-issue bot flags the dashboard, exempt it by label.

Two rules keep the dashboard useful as a repository grows:

  • Don't use its list of detected dependencies as an audit record. GitHub caps an issue body at 65,536 characters, so Renovate trims the list in a large repository. Check what the bot manages in a configuration test or a scheduled dry run, where truncation fails visibly.
  • Keep the pending list short, and give it an owner. People stop reading a dashboard with hundreds of open entries. Fix the cause in the grouping and scheduling policy: group related updates, widen the schedule until the queue clears, and name the team that works through it.