Repository navigation
Set host path for direct MSBuild builds - #55581
Merged
Merged
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 452f1417-5b58-4aa0-9182-e8c75f219a12
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses failures in device-aware dotnet test (MTP) and dotnet run paths that invoke MSBuild in-process (via ProjectInstance.Build / ProjectInstance.FromFile) without the usual forwarding setup that provides DOTNET_HOST_PATH. It factors the MSBuild-required environment setup into a disposable scope and uses it around direct evaluation/build operations, plus adds regression assertions in device test assets.
Changes:
- Added
MSBuildForwardingAppWithoutLogging.SetMSBuildRequiredEnvironmentVariables()to scope MSBuild-required env vars (includingDOTNET_HOST_PATH) and restore them on dispose. - Wrapped direct MSBuild evaluation/build calls in
dotnet rundevice-selection flows and MTP device flows with that environment scope. - Added test-asset MSBuild targets to assert
$(DOTNET_HOST_PATH)is set during device-target execution, and added adotnet testregression test that removesDOTNET_HOST_PATHfrom the test process environment.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.csproj | Adds a target-time assertion that $(DOTNET_HOST_PATH) is set for device-related targets. |
| test/TestAssets/TestProjects/DotnetRunDevices/DotnetRunDevices.csproj | Adds the same DOTNET_HOST_PATH assertion for run-device target execution. |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs | Adds a regression test ensuring direct device targets set DOTNET_HOST_PATH even if removed from the parent process environment. |
| src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs | Refactors env-var setup/restore into a reusable disposable scope and uses it for in-proc MSBuild execution. |
| src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs | Applies the environment scope around direct in-proc device deploy/run-argument MSBuild targets. |
| src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs | Applies the environment scope around MTP solution/project MSBuild operations and evaluation. |
| src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs | Applies the environment scope when evaluating projects to resolve target frameworks for --device. |
| src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs | Switches to the shared env-var scope instead of ad-hoc save/restore. |
| src/Cli/dotnet/Commands/Run/RunCommandSelector.cs | Applies the environment scope around direct project evaluation/restore/build target invocations for device selection. |
| src/Cli/dotnet/Commands/Run/RunCommand.cs | Applies the environment scope around project evaluation + ComputeRunArguments execution. |
Suppressed comments (1)
src/Cli/dotnet/Commands/Run/RunCommand.cs:596
- The
tryblock that scopesSetMSBuildRequiredEnvironmentVariables()is not closed before thefinallythat follows, which makes this method syntactically invalid (missing}beforefinally). This should be simplified to ausing (...) { ... }scope (or remove thetry/finallyentirely) so the environment scope is disposed correctly without an emptyfinallyblock.
using var _ = MSBuildForwardingAppWithoutLogging.SetMSBuildRequiredEnvironmentVariables();
project = EvaluateProject(ProjectFileFullPath, projectFactory, MSBuildArgs, logger);
ValidatePreconditions(project);
hasRuntimeEnvironmentVariableSupport = InvokeRunArgumentsTarget(project, NoBuild, logger, MSBuildArgs, EnvironmentVariables);
}
Evangelink
reviewed
Aug 4, 2026
Co-authored-by: Copilot App <[email protected]>
Evangelink
approved these changes
Aug 4, 2026
Co-authored-by: Copilot App <[email protected]> Copilot-Session: ea84fd72-34f1-4444-a407-ee5651625c9c
Evangelink
approved these changes
Aug 4, 2026
jonathanpeppers
enabled auto-merge (squash)
August 4, 2026 17:21
jonathanpeppers
added a commit
to dotnet/android
that referenced
this pull request
Aug 4, 2026
- **Dependency Updates**:
- From [11.0.0-beta.26365.101 to 11.0.0-beta.26401.101][3]
- Microsoft.DotNet.Arcade.Sdk
- Microsoft.DotNet.Build.Tasks.Feed
- From [0.11.5-preview.26365.101 to 0.11.5-preview.26401.101][3]
- Microsoft.DotNet.Cecil
- From [11.0.0-preview.7.26365.101 to 11.0.0-rc.1.26401.101][3]
- Microsoft.NET.ILLink
- Microsoft.NETCore.App.Ref
- From [11.0.100-preview.7.26365.101 to 11.0.100-rc.1.26401.101][3]
- Microsoft.NET.Sdk
- Microsoft.TemplateEngine.Authoring.Tasks
[3]: dotnet/dotnet@cb8306a...5da2de2
## Additional changes
- Run APK instrumentation through `dotnet test` and set `DOTNET_HOST_PATH` as a workaround pending dotnet/sdk#55581.
- Ensure nested MSBuild invocations include bound Java source JARs on the `javac` classpath.
- Temporarily skip the Mono APK smoke test due to dotnet/runtime#131760.
Co-authored-by: Jonathan Peppers <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Xiaoy312
added a commit
to unoplatform/Uno.microsoft-ui-reactor
that referenced
this pull request
Oct 29, 2026
`dotnet run -f net10.0-android` failed with MSB4221 "DOTNET_HOST_PATH is not set" when the app has a ProjectReference to an Uno library, as the in-repo samples have to Reactor.Uno: dotnet run builds DeployToDevice in its own process without the variable, DeployToDevice rebuilds the references, and Uno's EmbeddedResourceInjectorTask runs in a .NET task host that needs it. MSBuild takes DOTNET_HOST_PATH for a task host from each project's properties, so the package's targets and Reactor.Uno.csproj now set it from NetCoreRoot when the build doesn't have it. That covers Reactor.Uno and any library that references the package; an Uno library that doesn't reference Reactor still hits the SDK bug. Temporary, until the SDKs we support carry dotnet/sdk#55581 (in the .NET 11 SDK, not in 10.0.4xx). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
dotnet testMTP and device-awaredotnet runinvoke some MSBuild targets in-process throughProjectInstance.Build, bypassing the forwarding path that setsDOTNET_HOST_PATH. This can cause runtime bootstrap tasks, including Android ILLink targets, to fail with MSB4221.Use the existing MSBuild forwarding environment-variable helper as a scoped operation around project evaluation and each direct build. The scope restores the prior environment value immediately after each operation, so it does not leak into launched applications.
Add target-time device test assertions for
DOTNET_HOST_PATH. The MTP regression removes the variable from the test process, proving the direct build path supplies it; existing run device scenarios exercise the corresponding run targets.Tests:
GivenDotnetRunSelectsDevice(23 tests)GivenDotnetTestSelectsDevice(31 tests)src\Cli\dotnet\dotnet.csprojDebug build