Skip to content

Fix dotnet publish bundling appsettings.Local.json#26

Merged
MikeWills merged 2 commits into
masterfrom
fix/publish-excludes-local-secrets
Jul 10, 2026
Merged

Fix dotnet publish bundling appsettings.Local.json#26
MikeWills merged 2 commits into
masterfrom
fix/publish-excludes-local-secrets

Conversation

@MikeWills

Copy link
Copy Markdown
Owner

Summary

  • appsettings.Local.json is copied to the build output (dotnet build/dotnet run, F5 in Visual Studio) whenever it exists, for local dev convenience.
  • That same MSBuild rule also applied to dotnet publish, since CopyToPublishDirectory inherits CopyToOutputDirectory's value unless set explicitly.
  • CONTRIBUTING.md's "cutting a release" instructions use plain dotnet publish locally — so anyone building their own release from a checkout with real credentials in appsettings.Local.json would unknowingly bundle them into the distributable output. CI's release.yml was never at risk (its checkout never has this .gitignored file), but a local publish was.
  • Fix: pin CopyToPublishDirectory to Never on that item.

Test plan

  • dotnet build/dotnet test — clean, 84/84 passing
  • dotnet publish -r win-x64 --self-contained -o <scratch> — confirmed output only has appsettings.json, no appsettings.Local.json
  • dotnet build (simulating F5) — confirmed bin/Debug/net10.0/ still has both appsettings.json and appsettings.Local.json, unchanged from before this fix

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
https://claude.ai/code/session_01HGgBp8jugwf4PzZEJKrEL7

MikeWills and others added 2 commits July 9, 2026 22:10
appsettings.Local.json is copied to the build output (dotnet build/run,
F5 in Visual Studio) whenever it exists, for local dev convenience --
but that same MSBuild rule also applied to dotnet publish, since
CopyToPublishDirectory inherits CopyToOutputDirectory's value unless
set explicitly. CONTRIBUTING.md's "cutting a release" instructions use
plain dotnet publish locally, so anyone building their own release from
a checkout with real credentials in appsettings.Local.json would
unknowingly bundle them into the distributable output. CI's
release.yml was never at risk -- its checkout never has this
gitignored file.

Fixed by pinning CopyToPublishDirectory to Never on that item.
Verified: dotnet publish now excludes appsettings.Local.json from its
output, while a plain dotnet build (and F5) still copies it, unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGgBp8jugwf4PzZEJKrEL7
@MikeWills
MikeWills merged commit 9539adf into master Jul 10, 2026
2 checks passed
@MikeWills
MikeWills deleted the fix/publish-excludes-local-secrets branch July 10, 2026 03:38
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