Skip to content

Report MSBuild errors from dotnet test device deploy and run-argument builds - #55524

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/report-msbuild-errors-in-test-device-bui
Jul 30, 2026
Merged

Report MSBuild errors from dotnet test device deploy and run-argument builds#55524
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/report-msbuild-errors-in-test-device-bui

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Follow-up to #55502 (comment).

The problem

SolutionAndProjectUtility.DeployAndGetRunProperties builds DeployToDevice and ComputeRunArguments on a ProjectInstance, passing only the FacadeLogger returned by LoggerUtility.DetermineBinlogger(...). That logger is null unless the user passed /bl, so in the common case the build runs with no loggers at all: ProjectInstance.Build creates a fresh BuildParameters() and only populates Loggers when the argument is non-null — it does not fall back to the ProjectCollection's loggers. And even with -bl, FacadeLogger only forwards to BinaryLoggers, never to the console.

The result is that any MSBuild error in these targets is invisible and the user only sees:

Running the ComputeRunArguments target to discover run commands failed for this project. Fix the errors and warnings and run again.

with no errors or warnings printed anywhere. That is exactly what made #55502 (MSB4018 / duplicate Microsoft.NETCore.App) a binlog-only investigation.

dotnet run does not have this problem: RunCommand.InvokeRunArgumentsTarget always attaches a quiet console logger unless -noConsoleLogger was passed, and RunCommandSelector.GetLoggers does the same for the device-selection builds.

The fix

Add SolutionAndProjectUtility.CreateBuildLoggers, which yields the binlog facade logger (when present) plus a fresh console logger at quiet verbosity unless -noConsoleLogger was passed, and use it for both the DeployToDevice and ComputeRunArguments builds. Quiet verbosity keeps successful runs silent while still reporting errors and warnings. A fresh console logger is created per build, matching RunCommandSelector's comment about disposal across multiple Build() calls.

After the change, the failure looks like:

DotnetTestDevices.csproj(45,5): error : ComputeRunArguments failed as requested.
Running the ComputeRunArguments target to discover run commands failed for this project. Fix the errors and warnings and run again.

Tests

  • ItFailsWhenDeployToDeviceTargetFails now also asserts the underlying MSBuild error text is printed.
  • New ItFailsWhenComputeRunArgumentsTargetFails, with a FailComputeRunArguments hook added to the DotnetTestDevices test asset, covering the ComputeRunArguments path from the linked discussion.

Verified locally against a Debug redist build:

Filter Result
GivenDotnetTestSelectsDevice 30/30 passed
Microsoft.DotNet.Cli.Test.Tests 415 total, 389 passed, 26 skipped, 0 failed

The DeployToDevice and ComputeRunArguments builds in the MTP test path only
attached the binary logger, which is null unless -bl was passed and never
forwards to the console. Failures were therefore reported as 'fix the errors
and warnings and run again' with no error printed anywhere.

Attach a quiet console logger (unless -noConsoleLogger was passed), matching
what dotnet run does in RunCommand.InvokeRunArgumentsTarget.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8786482b-05a7-4dc4-a9a3-6848cb7433c3
Copilot AI review requested due to automatic review settings July 29, 2026 16:47
@Evangelink
Evangelink requested a review from a team as a code owner July 29, 2026 16:47

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.

Pull request overview

This PR improves the dotnet test device-deploy and run-argument discovery experience by ensuring MSBuild failures from the in-proc ProjectInstance.Build(...) calls are actually surfaced to the user (instead of failing with only a generic “fix errors and warnings” message).

Changes:

  • Attach a quiet console logger (unless -noConsoleLogger was passed) alongside the binlog facade logger for the DeployToDevice and ComputeRunArguments in-proc builds.
  • Extend device-selection tests to assert the underlying MSBuild error text is printed for both deploy and run-argument failures.
  • Add a test-asset hook to intentionally fail ComputeRunArguments for coverage.
Show a summary per file
File Description
test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.csproj Adds a BeforeTargets="ComputeRunArguments" failure hook to simulate MSBuild errors in that target.
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs Updates/extends tests to assert MSBuild error output is visible for deploy and compute-run-arguments failure paths.
src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs Introduces CreateBuildLoggers(...) and uses it for in-proc deploy + run-argument builds to ensure errors/warnings are logged.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@Evangelink
Evangelink enabled auto-merge July 29, 2026 16:51
…-msbuild-errors-in-test-device-bui

# Conflicts:
#	src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
@Evangelink
Evangelink merged commit f556100 into main Jul 30, 2026
21 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/report-msbuild-errors-in-test-device-bui branch July 30, 2026 11:47
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 31, 2026
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