Skip to content

Fix skipped target hooks in out-of-process builds - #15482

Merged
JanProvaznik merged 2 commits into
dotnet:mainfrom
AArnott:dev/andrew.arnott/preserve-hook-comparers-pr
Nov 9, 2026
Merged

JanProvaznik merged 2 commits into
dotnet:mainfrom
AArnott:dev/andrew.arnott/preserve-hook-comparers-pr

Conversation

@AArnott

@AArnott AArnott commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

When a complete project instance is transferred to an out-of-process worker, requesting build can execute Build while silently skipping its BeforeTargets and AfterTargets hooks. The transferred hook dictionaries lose their case-insensitive comparer. Preserve MSBuild's target-name comparison semantics across the transfer so hooks run regardless of the requested target casing, including builds initiated by Visual Studio.

The regression covers alternate target casing, canonical casing, and an in-process control, and checks that both hooks execute exactly once.

Preserve case-insensitive target hook lookups when transferring an entire ProjectInstance to an out-of-process worker. Otherwise a differently cased target name can execute its body while silently skipping its before and after hooks.

Co-authored-by: Copilot <[email protected]>
@AArnott
AArnott requested a balanced review from Copilot November 6, 2026 19:30
@AArnott
AArnott marked this pull request as ready for review November 6, 2026 19:33
@AArnott
AArnott temporarily deployed to copilot-pat-pool November 6, 2026 19:33 — with GitHub Actions Inactive
@AArnott
AArnott temporarily deployed to copilot-pat-pool November 6, 2026 19:33 — with GitHub Actions Inactive
@AArnott
AArnott temporarily deployed to copilot-pat-pool November 6, 2026 19:34 — with GitHub Actions Inactive

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.

🟡 Changes recommended

The deserialization comparer can merge distinct valid target names on .NET Framework x86/x64, overwriting hook lists and causing hooks to be skipped or associated with the wrong target.

1 open issue
What changed in this PR

This PR addresses skipped BeforeTargets and AfterTargets hooks when MSBuild transfers a complete project instance to an out-of-process worker and the requested target casing differs.

Changes:

  • Adds case-insensitive comparers when deserializing target-hook dictionaries.
  • Adds regression coverage for alternate and canonical target casing, plus an in-process control, verifying both hooks execute exactly once.
File Description
src/​Build/​Instance/​ProjectInstance.cs Adds comparers to deserialized before/after target-hook dictionaries.
src/​Build.UnitTests/​BackEnd/​BuildManager_Tests.cs Tests hook execution across target casing and process modes.

Review effort: Balanced

Comment thread src/Build/Instance/ProjectInstance.cs Resolved
@AArnott
AArnott temporarily deployed to copilot-pat-pool November 6, 2026 19:48 — with GitHub Actions Inactive
@AArnott
AArnott temporarily deployed to copilot-pat-pool November 6, 2026 19:49 — with GitHub Actions Inactive

@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.

MSBuild Target Authoring Conventions — LGTM

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com
  • patchdiff.githubusercontent.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"
    - "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by Expert Code Review (on open) for #15482 · copilot · gpt56 · 635.4 AIC · ⌖ 0.522 AIC · ⊞ 20.9K

@AArnott
AArnott temporarily deployed to copilot-pat-pool November 6, 2026 19:50 — with GitHub Actions Inactive
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@JanProvaznik
JanProvaznik merged commit 82b3880 into dotnet:main Nov 9, 2026
13 checks passed
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