-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Stage 3: Forward BuildProjectFile* callbacks from OOP TaskHost to worker node #13350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JanProvaznik
merged 14 commits into
dotnet:main
from
JanProvaznik:ibuildengine-callbacks-stage3
Apr 21, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9c0c6e6
Add IPC packets for BuildProjectFile callback
JanProvaznik bc2cb8a
Implement BuildProjectFile callback forwarding in OOP TaskHost
JanProvaznik ee02b2c
Add integration and serialization tests for TaskHost callbacks
JanProvaznik 42a662a
Update taskhost-threading.md with BuildProjectFile callback docs
JanProvaznik ad2bdac
remove redundant assertion
JanProvaznik 3896827
taskhosttask should not mask exception
JanProvaznik db5a40f
string.join only in Log.IsEnabled
JanProvaznik 05d9a06
crash on receive respondse when request not pending
JanProvaznik 460043f
clarify request id uniqueness
JanProvaznik 71a65bc
improve comment
JanProvaznik c6163be
throwinternalerror
JanProvaznik 023a16a
comments, harder asserts
JanProvaznik aebc348
configuration is constant across build
JanProvaznik 865b2cd
unknown packet error not trace
JanProvaznik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
src/Build.UnitTests/BackEnd/BuildProjectFileAndReportPidTask.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections; | ||
| using System.Diagnostics; | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
|
|
||
| namespace Microsoft.Build.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// A test task that reports its process ID and optionally calls BuildProjectFile | ||
| /// on a child project. Used by TaskHost reuse E2E tests to verify that a parent | ||
| /// task and a nested child task run in the same OOP TaskHost process. | ||
| /// </summary> | ||
| public class BuildProjectFileAndReportPidTask : Task | ||
| { | ||
| /// <summary> | ||
| /// Path to the project file to build. If empty, just reports PID without building. | ||
| /// </summary> | ||
| public string ProjectFile { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Semicolon-separated list of Property=Value pairs to pass as global properties. | ||
| /// </summary> | ||
| public string Properties { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// The process ID of the TaskHost running this task. | ||
| /// </summary> | ||
| [Output] | ||
| public int ProcessId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Whether the child build succeeded (only meaningful when ProjectFile is set). | ||
| /// </summary> | ||
| [Output] | ||
| public bool BuildSucceeded { get; set; } | ||
|
|
||
| public override bool Execute() | ||
| { | ||
| ProcessId = Process.GetCurrentProcess().Id; | ||
| Log.LogMessage(MessageImportance.High, $"TASKHOST_PID={ProcessId}"); | ||
|
|
||
| if (!string.IsNullOrEmpty(ProjectFile)) | ||
| { | ||
| Hashtable? globalProperties = null; | ||
| if (!string.IsNullOrEmpty(Properties)) | ||
| { | ||
| globalProperties = new Hashtable(); | ||
| foreach (string pair in Properties.Split(';')) | ||
| { | ||
| string[] parts = pair.Split(new[] { '=' }, 2); | ||
| if (parts.Length == 2) | ||
| { | ||
| globalProperties[parts[0].Trim()] = parts[1].Trim(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Hashtable targetOutputs = new(); | ||
| BuildSucceeded = BuildEngine.BuildProjectFile(ProjectFile, null, globalProperties, targetOutputs); | ||
| Log.LogMessage(MessageImportance.High, $"BuildProjectFile({ProjectFile}) = {BuildSucceeded}"); | ||
| } | ||
| else | ||
| { | ||
| BuildSucceeded = true; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
|
|
||
| namespace Microsoft.Build.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// A test task that calls IBuildEngine.BuildProjectFile to build another project. | ||
| /// Used by TaskHostCallback_Tests (in-process) and NetTaskHost_E2E_Tests (cross-runtime). | ||
| /// The E2E project includes this file via linked compile to avoid duplication. | ||
| /// </summary> | ||
| public class BuildProjectFileTask : Task | ||
| { | ||
| /// <summary> | ||
| /// Path to the project file to build. | ||
| /// </summary> | ||
| [Required] | ||
| public string ProjectFile { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Semicolon-separated list of targets to build. If empty, builds default targets. | ||
| /// </summary> | ||
| public string Targets { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Semicolon-separated list of Property=Value pairs to pass as global properties. | ||
| /// </summary> | ||
| public string Properties { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Whether the child build succeeded. | ||
| /// </summary> | ||
| [Output] | ||
| public bool BuildSucceeded { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Target output items from the child build (if any). | ||
| /// </summary> | ||
| [Output] | ||
| public ITaskItem[] OutputItems { get; set; } = []; | ||
|
|
||
| public override bool Execute() | ||
| { | ||
| string[]? targetNames = null; | ||
| if (!string.IsNullOrEmpty(Targets)) | ||
| { | ||
| targetNames = Targets.Split(';'); | ||
| } | ||
|
|
||
| Hashtable? globalProperties = null; | ||
| if (!string.IsNullOrEmpty(Properties)) | ||
| { | ||
| globalProperties = new Hashtable(); | ||
| foreach (string pair in Properties.Split(';')) | ||
| { | ||
| string[] parts = pair.Split('='); | ||
| if (parts.Length == 2) | ||
| { | ||
| globalProperties[parts[0].Trim()] = parts[1].Trim(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Hashtable targetOutputs = new(); | ||
|
|
||
| BuildSucceeded = BuildEngine.BuildProjectFile(ProjectFile, targetNames, globalProperties, targetOutputs); | ||
|
|
||
| // Collect all targets' outputs as ITaskItem[] if available. | ||
| if (BuildSucceeded && targetOutputs.Count > 0) | ||
| { | ||
| var items = new List<ITaskItem>(); | ||
| foreach (DictionaryEntry entry in targetOutputs) | ||
| { | ||
| if (entry.Value is ITaskItem[] taskItems) | ||
| { | ||
| items.AddRange(taskItems); | ||
| } | ||
| } | ||
|
|
||
| OutputItems = items.ToArray(); | ||
| } | ||
|
|
||
| Log.LogMessage(MessageImportance.High, $"BuildProjectFile({ProjectFile}) = {BuildSucceeded}, OutputItems={OutputItems.Length}"); | ||
| return true; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.