Fix MSBuildTask0002 analyzer warnings in already-migrated tasks#13466
Open
JanProvaznik wants to merge 1 commit intodotnet:mainfrom
Open
Fix MSBuildTask0002 analyzer warnings in already-migrated tasks#13466JanProvaznik wants to merge 1 commit intodotnet:mainfrom
JanProvaznik wants to merge 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses MSBuildTask0002 analyzer warnings by switching already-IMultiThreadableTask tasks to use TaskEnvironment-based APIs (and AbsolutePath) instead of direct Environment.GetEnvironmentVariable / Path.GetFullPath, improving correctness in multithreaded execution modes.
Changes:
- Update path canonicalization and path-type plumbing to use
TaskEnvironment.GetAbsolutePath(...).GetCanonicalForm()andAbsolutePathwhere appropriate. - Refactor
Copyto read relevant environment variables viaTaskEnvironmentper-task-execution (instead of static reads) and adjust related unit tests. - Add targeted
#pragmasuppressions in pre-ChangeWave branches wherePath.GetFullPathis still required for behavior compatibility.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/Unzip.cs | Use TaskEnvironment + AbsolutePath canonicalization for zip extraction destination validation. |
| src/Tasks/NativeMethods.cs | Change MoveFileEx wrapper to use AbsolutePath parameters. |
| src/Tasks/ListOperators/FindUnderPath.cs | Add MSBuildTask0002 suppression in pre-ChangeWave branch around Path.GetFullPath. |
| src/Tasks/FileIO/GetFileHash.cs | Strengthen ComputeHash signature to accept AbsolutePath. |
| src/Tasks/Copy.cs | Replace static environment-variable reads with per-Execute() TaskEnvironment reads; adjust symlink retry flags accordingly. |
| src/Tasks/AssignTargetPath.cs | Add MSBuildTask0002 suppression in pre-ChangeWave branch around Path.GetFullPath. |
| src/Tasks.UnitTests/Copy_Tests.cs | Remove reliance on Copy.RefreshInternalEnvironmentValues() after env-var handling refactor. |
Replace direct Environment.GetEnvironmentVariable and Path.GetFullPath calls in tasks that already implement IMultiThreadableTask, addressing analyzer warnings in the 'Linux Core Multithreaded Mode' CI leg. Changes: - Copy.cs: Convert static env var reads to instance fields initialized from TaskEnvironment.GetEnvironmentVariable() at the start of Execute(). This is MT-safe since each task instance gets its own TaskEnvironment. Constants remain on Copy for test access. RefreshInternalEnvironmentValues() is now a no-op (env vars are read fresh per Execute call). - GetFileHash.cs: Change ComputeHash parameter from string to AbsolutePath to preserve type safety through to File.OpenRead call. - Unzip.cs: Replace Path.GetFullPath with TaskEnvironment.GetAbsolutePath().GetCanonicalForm() using AbsolutePath type. GetCanonicalForm resolves '..' for zip slip protection. - FindUnderPath.cs: Pragma-suppress MSBuildTask0002 in pre-ChangeWave branches where Path.GetFullPath is called on already-absolute paths from TaskEnvironment.GetAbsolutePath (only canonicalizes, CWD not consulted). - AssignTargetPath.cs: Same pragma-suppress pattern as FindUnderPath. Remaining MSBuildTask0005 (transitive) warnings in Copy/Move should be addressed by improving the ThreadSafeTaskAnalyzer's AbsolutePath recognition in transitive call chains. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b1e1236 to
aabceed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace direct Environment.GetEnvironmentVariable and Path.GetFullPath calls in tasks that already implement IMultiThreadableTask, addressing analyzer warnings in the 'Linux Core Multithreaded Mode' CI leg.
Changes: