Repository navigation
Extract DebugTrace into a standalone Framework class - #14494
Conversation
Move the MSBUILDENABLEDEBUGTRACING-gated diagnostic tracing helper out of FrameworkErrorUtilities and the Shared ErrorUtilities forwarders into a new standalone Microsoft.Build.Framework.DebugTrace class with a DebugTrace.WriteLine API. This gives the functionality a clear home and drops the tracing concern from the error-utility types. The new WriteLine overloads take the message first and an optional [CallerMemberName] category last, so most callers no longer need to pass their own member name as the category. The interpolated-string overload defers formatting via WriteLineInterpolatedStringHandler, keeping calls nearly free when tracing is disabled. - Add src/Framework/DebugTrace.cs (internal static class + nested handler). - Remove DebugTraceMessage and DebugTraceInterpolatedStringHandler from src/Framework/ErrorUtilities.cs, along with the now-unused usings. - Remove the DebugTraceMessage forwarders from src/Shared/ErrorUtilities.cs. - Update all ToolLocationHelper.cs and EngineFileUtilities.cs callers to DebugTrace.WriteLine, dropping redundant category arguments where the category matched the enclosing member and preserving explicit categories where it did not.
There was a problem hiding this comment.
Pull request overview
This PR refactors the MSBUILDENABLEDEBUGTRACING-gated diagnostic tracing helper by moving it out of FrameworkErrorUtilities (and removing the corresponding Shared.ErrorUtilities forwarders) into a dedicated internal Microsoft.Build.Framework.DebugTrace type. This gives the tracing helper a clearer ownership boundary and keeps error-utility types focused on validation/exception responsibilities.
Changes:
- Introduces
Microsoft.Build.Framework.DebugTracewithWriteLineoverloads (including an interpolated-string-handler overload to defer formatting). - Removes the old
FrameworkErrorUtilities.DebugTraceMessageimplementation and theShared.ErrorUtilities.DebugTraceMessageforwarders. - Updates call sites in
ToolLocationHelperandEngineFileUtilitiesto useDebugTrace.WriteLine.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Utilities/ToolLocationHelper.cs | Switches diagnostic trace calls from ErrorUtilities.DebugTraceMessage to DebugTrace.WriteLine (dropping explicit category where it matches caller). |
| src/Shared/ErrorUtilities.cs | Removes the DebugTraceMessage forwarders into FrameworkErrorUtilities. |
| src/Framework/ErrorUtilities.cs | Removes the embedded debug tracing implementation from FrameworkErrorUtilities. |
| src/Framework/DebugTrace.cs | Adds new standalone DebugTrace helper with string + interpolated-string-handler overloads. |
| src/Build/Utilities/EngineFileUtilities.cs | Updates wildcard-expansion tracing to use DebugTrace.WriteLine. |
There was a problem hiding this comment.
Review Summary
Verdict: LGTM with minor notes
Clean refactoring that correctly moves debug tracing into a dedicated class with proper interpolated string handler support. The [CallerMemberName] default for category is a nice touch — all call sites where category is omitted have method names matching the old explicit category strings.
Findings
No blocking or major issues found. All 24 dimensions checked:
- Backwards Compatibility — LGTM.
DebugTraceisinternal, old API wasinternal, no public surface change. - Concurrency — LGTM.
s_enabledisstatic readonly(initialized once).Trace.WriteLineis thread-safe. - Performance — LGTM. The interpolated string handler correctly defers formatting when tracing is disabled.
- Correctness — LGTM. The
readonlyon handler methods works becauseStringBuilderHelperholds a reference-typeStringBuilder?; the defensive copy still shares the same instance. - API Surface — LGTM. All new types are
internal. - Test Coverage — Pre-existing gap; the old code had no tests either. Not a regression.
- All other dimensions (ChangeWave, String Comparison, Targets, SDK Integration, Cross-Platform, Evaluation, Security, etc.) — LGTM. No behavioral changes to gate, no new warnings, no target/evaluation changes, no security concerns.
Minor Note (NIT)
In GetApiContractReferences (ToolLocationHelper.cs ~line 1136), the log message content was intentionally changed from logging TargetPlatformIdentifier/Version to logging contract.Name/contract.Version. This is a diagnostic improvement — the old message was copy-paste wrong for the loop context. Worth confirming this was intentional.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpg
To allow these domains, add them to the
network.allowedlist in your workflow frontmatter:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
Generated by Expert Code Review (on open) for #14494 · 139.9 AIC · ⌖ 7.57 AIC · ⊞ 5K
|
Thanks @JanProvaznik! |
Pulls the
MSBUILDENABLEDEBUGTRACING-gated diagnostic tracing helper out ofFrameworkErrorUtilities(and itsShared.ErrorUtilitiesforwarders) into a dedicatedMicrosoft.Build.Framework.DebugTraceclass, giving the functionality a clear home and freeing the error-utility types of an unrelated concern.DebugTrace.WriteLinetakes the message first and an optional[CallerMemberName]category last, so most callers no longer pass their own member name explicitly. The interpolated-string overload keeps calls nearly free when tracing is disabled by deferring formatting until it's actually needed.Callers in
ToolLocationHelperandEngineFileUtilitiesare updated accordingly — dropping the category argument where it matched the enclosing member and keeping it explicit where it didn't. No behavior change.