Skip to content

Add Transactional mode for WriteLinesToFile#12627

Merged
SimaTian merged 32 commits intodotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/add-transactional-mode-for-WriteLinesToFile
Dec 17, 2025
Merged

Add Transactional mode for WriteLinesToFile#12627
SimaTian merged 32 commits intodotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/add-transactional-mode-for-WriteLinesToFile

Conversation

@huulinhnguyen-dev
Copy link
Contributor

@huulinhnguyen-dev huulinhnguyen-dev commented Oct 9, 2025

Fixes #
Add Transactional mode for WriteLinesToFile to allow multiple projects attempt to write to the same file simultaneously #12061

Context

The WriteLinesToFile MSBuild task encountered errors during parallel builds due to multiple MSBuild.exe processes attempting to write to the same file concurrently. This PR enhances the Transactional mode to ensure atomic file operations

Changes Made

  • Add Transactional mode for WriteLinesToFile
  • Implement saves files atomically with the help of a temporary file

Testing

Test was performed by using 8 project files at the same time, trying to write to one file with Transactional = true.

Notes

@KirillOsenkov
Copy link
Member

I'm not sure we should introduce a new Transactional element on the task XML.

Instead we should probably have an environment variable to opt into this. Longer term after a lot of testing we should make it the default. After another long time we should delete the non-transactional branch.

@rainersigwald
Copy link
Member

I'm not sure we should introduce a new Transactional element on the task XML.

Instead we should probably have an environment variable to opt into this. Longer term after a lot of testing we should make it the default. After another long time we should delete the non-transactional branch.

I would make it the default now, but behind a changewave so if it causes problems a user can report it then turn it off while we figure out what to change.

@huulinhnguyen-dev huulinhnguyen-dev force-pushed the dev/huulinhnguyen/add-transactional-mode-for-WriteLinesToFile branch from efe3a58 to 698b421 Compare November 11, 2025 13:08
@huulinhnguyen-dev huulinhnguyen-dev force-pushed the dev/huulinhnguyen/add-transactional-mode-for-WriteLinesToFile branch from 90a82a8 to b5bb9a2 Compare November 12, 2025 07:09
@huulinhnguyen-dev huulinhnguyen-dev marked this pull request as draft November 12, 2025 09:24
@huulinhnguyen-dev huulinhnguyen-dev force-pushed the dev/huulinhnguyen/add-transactional-mode-for-WriteLinesToFile branch from 1fdb03f to 816ca09 Compare November 13, 2025 05:28
@huulinhnguyen-dev huulinhnguyen-dev marked this pull request as ready for review November 13, 2025 06:27
Copy link
Member

@SimaTian SimaTian left a comment

Choose a reason for hiding this comment

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

I saw several places where I'm seeking additional clarification.

The only change I think will be necessary is to update the changewave - though I'll defer that decision to @baronfel . The rest are more of a discussion openers.

Other than that I have few places that I'm suspicious about. This is not the fault of your implementation but with the overall Task design.

@baronfel
Copy link
Member

A new change wave is 100% required - after a release we should essentially never add to that change wave.

@SimaTian SimaTian merged commit 79dc2dc into dotnet:main Dec 17, 2025
10 checks passed
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.

5 participants