-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Migrate WriteCodeFragment task to use TaskEnvironment API #13169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
JanProvaznik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Migrates WriteCodeFragment to the TaskEnvironment API so relative paths are resolved against the project directory (not process current directory), enabling thread-safe execution in multithreaded MSBuild mode.
Changes:
- Mark
WriteCodeFragmentas thread-safe ([MSBuildMultiThreadableTask]) and implementIMultiThreadableTaskwith aTaskEnvironmentproperty. - Resolve output paths via
TaskEnvironment.GetAbsolutePath()and use the resolved absolute path for directory creation, file writes, and lock diagnostics. - Update
WriteCodeFragmentunit tests to initializeTaskEnvironmentviaTaskEnvironmentHelper.CreateForTest().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Tasks/WriteCodeFragment.cs | Adds multithreadable task support and uses TaskEnvironment to resolve paths before I/O. |
| src/Tasks.UnitTests/WriteCodeFragment_Tests.cs | Updates tests to set TaskEnvironment on task instances. |
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
|
@copilot create a test for the case when OutputDirectory is relative, OutputFile is not passed in that in that case we receive a relative OutputFile |
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Added test |
|
@copilot Stack trace |
…codefragment-task
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
... Fixed in 5e4d0d4. The |
Context
Thread-safe tasks must avoid global process state (working directory, environment variables).
WriteCodeFragmentuses relative paths resolved against the current working directory, making it unsafe for multithreaded execution.Changes Made
[MSBuildMultiThreadableTask]attribute and implementIMultiThreadableTaskTaskEnvironment.GetAbsolutePath()to resolve paths before file operations:FileUtilities.GetTemporaryFile(),FileUtilities.EnsureDirectoryExists(),File.WriteAllText(), andLockCheck.GetLockedFileMessage()TaskEnvironment = TaskEnvironmentHelper.CreateForTest()OutputDirectoryis relative andOutputFileis not specified, the resultingOutputFileoutput remains relative (matching original behavior)Testing
All 52 WriteCodeFragment tests pass, including:
RelativeOutputDirectoryProducesRelativeOutputFilethat verifies whenOutputDirectoryis relative andOutputFileis not passed, the resultingOutputFileis also relativeCommentIsInvariantCulturetests (added in main) now haveTaskEnvironmentinitializedNotes
None.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.