Skip to content

Add BuildCheck for WriteLinesToFile without Overwrite - #14690

Merged
AR-May merged 2 commits into
dotnet:mainfrom
iamhaseebn:fix-writelinestofile-overwrite-check
Oct 16, 2026
Merged

AR-May merged 2 commits into
dotnet:mainfrom
iamhaseebn:fix-writelinestofile-overwrite-check

Conversation

@iamhaseebn

Copy link
Copy Markdown
Contributor

Fixes #11927

Context

WriteLinesToFile defaults Overwrite to false, so repeated incremental builds can append duplicate content when Overwrite is omitted. This adds the proposed opt-in style check without changing existing build behavior.

Changes Made

  • Add opt-in built-in check BC0303 for WriteLinesToFile invocations that omit Overwrite.
  • Preserve invocations with explicit Overwrite="true" or Overwrite="false" and match MSBuild names case-insensitively.
  • Register the check and add resource strings and BuildCheck documentation.
  • Add focused coverage for omitted, explicit, and case-insensitive task and parameter names.

Testing

  • ./build.sh -v quiet - passed with zero warnings or errors.
  • All 7 focused WriteLinesToFileBuildCheck tests - passed.
  • Complete BuildCheck suite - 238 passed with zero failures and one expected Windows-only skip.
  • Bootstrap sample build, help output, and end-to-end BC0303 diagnostic verification - passed.

Notes

The check is opt-in, so existing builds are unaffected unless it is explicitly enabled.

@ViktorHofer

Copy link
Copy Markdown
Member

cc @baronfel in case you have an opinion here. @AR-May and I are OK with requiring to specify the Overwrite metadata under the assumption that this build check is not enabled by default.

@baronfel

Copy link
Copy Markdown
Member

Love it, thanks for the contribution!

@AR-May AR-May left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed review! The PR looks good overall to me. I just have a couple of points I’d like to see addressed.

Comment thread documentation/specs/BuildCheck/Codes.md Resolved
@AR-May

AR-May commented Oct 16, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@AR-May
AR-May enabled auto-merge (squash) October 16, 2026 09:16
@AR-May
AR-May disabled auto-merge October 16, 2026 09:17
@AR-May
AR-May merged commit 1da4fc4 into dotnet:main Oct 16, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn about WriteLinesToFile default behavior which is Append

5 participants