Skip to content

Conversation

@rainersigwald
Copy link
Member

Some tests were failing when run from Visual Studio because they were running in a .NET 9 process launched as TestHost.exe, not in a dotnet.exe host. That caused TaskHost launching to try to run TestHost.exe MSBuild.dll which failed, as TestHost isn't a general-purpose launcher.

Add another fallback to GetCurrentHost() to fall back to the current shared framework's parent dotnet.exe, if we can find it.

Some tests were failing when run from Visual Studio because they were
running in a .NET 9 process launched as TestHost.exe, not in a dotnet.exe
host. That caused TaskHost launching to try to run 'TestHost.exe MSBuild.dll'
which failed, as TestHost isn't a general-purpose launcher.

Add another fallback to GetCurrentHost to fall back to the current
shared framework's parent dotnet.exe, if we can find it.
Copilot AI review requested due to automatic review settings June 5, 2025 16:09
Copy link
Contributor

Copilot AI left a comment

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 enhances the host detection logic for .NET processes by adding a fallback that targets the parent dotnet.exe when running under TestHost.exe.

  • Changed the return type of GetCurrentHost to allow null values.
  • Added a new fallback branch to inspect EnvironmentUtilities.ProcessPath and, if necessary, derive the dotnet.exe path from the runtime directory.
Comments suppressed due to low confidence (1)

src/Build/BackEnd/Components/Communications/CurrentHost.cs:48

  • The use of hard-coded folder levels (4) can reduce clarity; consider defining a named constant to indicate the intended directory depth for improved maintainability.
dotnetExe = Path.Combine(FileUtilities.GetFolderAbove(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), 4), dotnetExeName);

@rainersigwald rainersigwald enabled auto-merge (squash) June 5, 2025 20:13
@rainersigwald rainersigwald merged commit 8d89e25 into dotnet:main Jun 6, 2025
10 checks passed
@rainersigwald rainersigwald deleted the tolerate-testhost.exe branch June 6, 2025 08:12
JanProvaznik pushed a commit to JanProvaznik/msbuild that referenced this pull request Jun 12, 2025
Some tests were failing when run from Visual Studio because they were
running in a .NET 9 process launched as `TestHost.exe`, not in a `dotnet.exe`
host. That caused TaskHost launching to try to run `TestHost.exe MSBuild.dll`
which failed, as TestHost isn't a general-purpose launcher.

Add another fallback to `GetCurrentHost` to fall back to the current
shared framework's parent `dotnet.exe`, if we can find it.
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.

3 participants