-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix task host launch regressions from apphost support #13325
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
YuliiaKovalova
merged 4 commits into
main
from
dev/ykovalova/fix-apphost-task-host-launch
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7b6924e
Fix task host launch regressions from apphost support (#13175)
YuliiaKovalova 7cc4928
Add CLR2 task host e2e regression tests
YuliiaKovalova e97459f
cover clr2 with the test
YuliiaKovalova 783c2ea
Update src/Build.UnitTests/CLR2TaskHost_E2E_Tests.cs
YuliiaKovalova 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.IO; | ||
| using Microsoft.Build.UnitTests; | ||
| using Microsoft.Build.UnitTests.Shared; | ||
| using Shouldly; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Build.Engine.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// End-to-end tests for the CLR2 task host (MSBuildTaskHost.exe). | ||
| /// These tests explicitly force tasks to run out-of-proc in CLR2 via | ||
| /// <c>TaskFactory="TaskHostFactory"</c> and <c>Runtime="CLR2"</c>, | ||
| /// exercising the CLR2 branch in <c>ResolveNodeLaunchConfiguration</c>. | ||
| /// </summary> | ||
| public class CLR2TaskHost_E2E_Tests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public CLR2TaskHost_E2E_Tests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that the CLR2 task host (MSBuildTaskHost.exe) can be launched and connected to | ||
| /// when a task explicitly requests Runtime="CLR2" with TaskHostFactory. | ||
| /// | ||
| /// Regression test for the apphost changes (PR #13175) that replaced the three-branch | ||
| /// ResolveNodeLaunchConfiguration with a two-branch version, losing the CLR2-specific path: | ||
| /// 1. Empty command-line args (MSBuildTaskHost.Main() takes no arguments) | ||
| /// 2. Handshake with toolsDirectory set to the EXE's directory so the pipe name | ||
| /// salt matches what the child process computes on startup | ||
| /// Without these, the parent and child compute different pipe name hashes → MSB4216. | ||
| /// </summary> | ||
| [WindowsNet35OnlyFact] | ||
| public void ExplicitCLR2TaskHostFactory_RunsTaskSuccessfully() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(_output); | ||
| TransientTestFolder testFolder = env.CreateFolder(createFolder: true); | ||
|
|
||
| string projectContent = """ | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <!-- Force Exec to run out-of-proc in the CLR2 task host (MSBuildTaskHost.exe) --> | ||
| <UsingTask TaskName="Microsoft.Build.Tasks.Exec" | ||
| AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" | ||
| TaskFactory="TaskHostFactory" | ||
| Runtime="CLR2" /> | ||
|
|
||
| <Target Name="Build"> | ||
| <Exec Command="echo CLR2TaskHostSuccess" /> | ||
| </Target> | ||
| </Project> | ||
| """; | ||
|
|
||
| string projectPath = Path.Combine(testFolder.Path, "CLR2ExplicitTest.proj"); | ||
| File.WriteAllText(projectPath, projectContent); | ||
|
|
||
| string testOutput = RunnerUtilities.ExecBootstrapedMSBuild( | ||
| $"\"{projectPath}\" -v:n", | ||
| out bool success, | ||
| outputHelper: _output); | ||
|
|
||
|
|
||
| // MSB4216 occurs when the parent can't connect to MSBuildTaskHost.exe — | ||
| // either due to handshake salt mismatch (missing toolsDirectory) or wrong process routing. | ||
| testOutput.ShouldNotContain("MSB4216", customMessage: "CLR2 task host connection should succeed with correct handshake salt and empty command-line args"); | ||
|
|
||
| success.ShouldBeTrue(customMessage: "Task explicitly requesting CLR2 + TaskHostFactory should execute in MSBuildTaskHost.exe"); | ||
|
|
||
| // Verify the task actually ran by checking for its output. | ||
| testOutput.ShouldContain("CLR2TaskHostSuccess", customMessage: "Exec task output should be visible, confirming it ran in CLR2 task host"); | ||
| } | ||
| } |
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
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
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
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.