Repository navigation
Detect environment-dependent temp helpers in TaskAnalyzer - #14975
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: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The behavioral change is well-scoped to analyzer detection and is covered by new direct/transitive regression tests, with only minor test-harness consistency nits noted.
Pull request overview
This PR closes a detection gap in the TaskAnalyzer by flagging additional “temp helper” APIs that depend on process-global TMP/TEMP state, and updates analyzer guidance/docs to recommend suppression-with-justification until a TaskEnvironment alternative exists.
Changes:
- Adds
Directory.CreateTempSubdirectory(string)andTempFileCollection()(parameterless ctor) to the banned API list underApiCategory.TaskEnvironment. - Updates TaskAnalyzer README to document the new temp-helper bans and clarify suppression guidance/limitations.
- Extends direct + transitive analyzer tests to cover the newly banned APIs and ensure
Path.GetRandomFileName()and explicit-directoryTempFileCollectionusage remain allowed.
File summaries
| File | Description |
|---|---|
| src/TaskAnalyzer/README.md | Documents additional temp-helper bans and clarifies suppression guidance/limitations. |
| src/TaskAnalyzer/BannedApiDefinitions.cs | Adds new banned API entries and aligns temp-helper messaging with “suppress with justification” guidance. |
| src/TaskAnalyzer.Tests/TransitiveCallChainAnalyzerTests.cs | Adds transitive-call coverage for the new banned temp helpers. |
| src/TaskAnalyzer.Tests/TestHelpers.cs | Adds System.CodeDom reference for test compilations so TempFileCollection can be exercised. |
| src/TaskAnalyzer.Tests/MultiThreadableTaskAnalyzerTests.cs | Adds direct analyzer coverage for CreateTempSubdirectory and TempFileCollection() patterns, plus permitted cases. |
Review details
Suppressed comments (1)
src/TaskAnalyzer.Tests/MultiThreadableTaskAnalyzerTests.cs:1330
- This test is scoped to the direct analyzer (the code under test is entirely inside the task type). Using
GetAllDiagnosticsAsyncadds the transitive analyzer without increasing coverage, and it makes failures harder to interpret. PreferGetDiagnosticsAsynchere; keepGetAllDiagnosticsAsyncfor tests that intentionally exercise helper-call analysis.
{
var diags = await GetAllDiagnosticsAsync($$"""
using System.CodeDom.Compiler;
using Microsoft.Build.Framework;
public class MyTask : Microsoft.Build.Utilities.Task, IMultiThreadableTask
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
The CreateTempSubdirectory and TempFileCollection tests exercise code entirely inside the task type, so running the transitive analyzer adds no coverage and makes failures harder to interpret. PathGetRandomFileName_DirectAndTransitive_NoDiagnostics keeps GetAllDiagnosticsAsync since it intentionally covers a helper call chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
🟢 Approval recommended
The changes are consistent across analyzer definitions, documentation, and test coverage, and I didn’t find correctness or maintainability issues in the updated logic.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
Context
Directory.CreateTempSubdirectory()depends on the same process-global temp environment asPath.GetTempPath(), but escaped both direct and transitive diagnostics.Changes Made
Directory.CreateTempSubdirectory(string)and parameterlessTempFileCollection(), identified by the BCL audit.TaskEnvironmentalternative exists.Testing
Regression coverage for direct/transitive calls, omitted/null/empty/named prefixes, and permitted
GetRandomFileName()and explicit-directoryTempFileCollectionusage.Notes
TempFileCollection(tempDir)overloads remain allowed. Their null/empty-directory fallback still escapes detection; this limitation is documented.