Skip to content

Extract DebugTrace into a standalone Framework class - #14494

Merged
JanProvaznik merged 1 commit into
dotnet:mainfrom
DustinCampbell:debugtrace
Jul 23, 2026
Merged

JanProvaznik merged 1 commit into
dotnet:mainfrom
DustinCampbell:debugtrace

Conversation

@DustinCampbell

Copy link
Copy Markdown
Member

Pulls the MSBUILDENABLEDEBUGTRACING-gated diagnostic tracing helper out of FrameworkErrorUtilities (and its Shared.ErrorUtilities forwarders) into a dedicated Microsoft.Build.Framework.DebugTrace class, giving the functionality a clear home and freeing the error-utility types of an unrelated concern.

DebugTrace.WriteLine takes 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 ToolLocationHelper and EngineFileUtilities are updated accordingly — dropping the category argument where it matched the enclosing member and keeping it explicit where it didn't. No behavior change.

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.
Copilot AI review requested due to automatic review settings July 22, 2026 22:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.DebugTrace with WriteLine overloads (including an interpolated-string-handler overload to defer formatting).
  • Removes the old FrameworkErrorUtilities.DebugTraceMessage implementation and the Shared.ErrorUtilities.DebugTraceMessage forwarders.
  • Updates call sites in ToolLocationHelper and EngineFileUtilities to use DebugTrace.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.

Comment thread src/Utilities/ToolLocationHelper.cs Resolved
Comment thread src/Framework/DebugTrace.cs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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. DebugTrace is internal, old API was internal, no public surface change.
  • Concurrency — LGTM. s_enabled is static readonly (initialized once). Trace.WriteLine is thread-safe.
  • Performance — LGTM. The interpolated string handler correctly defers formatting when tracing is disabled.
  • Correctness — LGTM. The readonly on handler methods works because StringBuilderHelper holds a reference-type StringBuilder?; 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.allowed list 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

@JanProvaznik
JanProvaznik merged commit ebf68ed into dotnet:main Jul 23, 2026
19 checks passed
@DustinCampbell

Copy link
Copy Markdown
Member Author

Thanks @JanProvaznik!

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 4649aa7a Deployed Jul 22, 2026 by DustinCampbell via conclusion #531
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.

4 participants