Repository navigation
Fix flaky Hex1bNativePublishingTests: read MSBuild query results from -getResultOutputFile - #21524
Conversation
Under CI load the dotnet CLI can fail to reach the MSBuild server and print 'MSBuild server unavailable: ... Falling back to an in-process build.' to standard output after the -getItem/-getProperty JSON. The tests parsed raw stdout, so JsonDocument.Parse failed on the trailing 'M'. Read query results from MSBuild's -getResultOutputFile instead and add a regression test that injects the exact fallback line through a dotnet wrapper. Fixes #20799 Fixes #20272 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21524Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21524" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
The Windows regression test launches a .cmd wrapper directly with shell execution disabled, causing Process.Start to throw before MSBuild runs.
1 open issue
What changed in this PR
This PR addresses flaky MSBuild query parsing in infrastructure tests by separating query results from CLI diagnostics, targeting the failures reported in #20799 and #20272.
Changes:
- Reads all MSBuild property and item queries in the class through
-getResultOutputFile. - Adds a regression test that injects the MSBuild-server fallback diagnostic into stdout while preserving native-asset assertions.
- Retains captured diagnostics for failure reporting.
| File | Description |
|---|---|
tests/Infrastructure.Tests/Hex1bNativePublishingTests.cs |
Adds file-backed query results and diagnostic-injection regression coverage. |
Review effort: Balanced
Address review feedback: route RunDotNetAsync through the shared ProcessStartInfoHelper.SetCommand so .cmd wrappers run via cmd.exe with correct argument quoting while stdout/stderr stay redirected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests selector1 / 100 PR test projects · 0 PR jobs, from 2 changed files. Selected PR test projects (1 / 100)
Selected PR jobs (0)none How these were chosen — grouped by what changed🧪 🧪 Job reasonsnone Selection computed for commit |
|
✅ No documentation update needed. docs_optional → test_only. No signals triggered (signal_count == 0); the change fixes a flaky infrastructure test (Hex1bNativePublishingTests) by reading MSBuild results from -getResultOutputFile. Only test files changed, with no user-facing surface. |

Description
Hex1bNativePublishingTests.NativeAssetsKeepTheirLayoutAndContentsfails intermittently onInfrastructure (ubuntu-latest)with:Root cause
The MSBuild JSON is not truncated. In every failing log I checked (runs 37668103720, 37782413043 and 35756256834), the complete
-getItemJSON is followed on stdout by the dotnet CLI's MSBuild-server client fallback diagnostic:With SDK 11, MSBuild server is used by default for invocations that run a target (
-t:CopyTestFiles -getItem:...). When the runner is loaded (heartbeat showed CPU 97% in run 37668103720), the client can't connect in time, falls back to an in-process build and prints that line after the results. The tests parsed raw stdout, soJsonDocument.Parsefailed on the trailingM.Other tests in this repo already guard against this exact message:
MicrosoftTestingPlatformTestsuses-getResultOutputFile, andTemplateManifestTestEnvironmentusesDOTNET_CLI_USE_MSBUILD_SERVER=0.Fix
The test now reads its MSBuild query results from
-getResultOutputFile:<path>instead of stdout.RunMSBuildQueryAsynchelper appends the switch and returns the file contents.-getProperty/-getItemcaller in the class now uses it. That covers the four JSON parsers and the single-propertyBundle.projConfigurationcheck, which compared trimmed stdout and was exposed to the same noise.No assertions were weakened, and no sleeps or retries were added.
Regression test
NativeAssetsIgnoreMSBuildServerFallbackDiagnosticsruns the real native-asset query, with all of its existing assertions, through adotnetwrapper (.shon Unix,.cmdon Windows). The wrapper runs the real CLI and then writes the exact CI fallback line to stdout. The test also asserts the line was captured, so it cannot pass by skipping the noisy scenario.'M' is invalid after a single JSON value. Expected end of data. LineNumber: 209, identical to CIHex1bNativePublishingTestsclass (43 tests) with 43/43 passing each timeLocal runs used Linux and SDK 11.0.100-rc.2.
Denominator
5 tracked occurrences across both issues (2026-09-21 to 2026-10-08; 3 on
main, 2 on PRs), against about 1,484ci.ymlruns from 2026-09-21 to 2026-10-07. Different theory rows failed (win-x64andwin-arm64, with and without single file), which fits noise from the environment rather than one data row.I noticed that
ResourceGeneratorMetadataTestsalso parses mergedmsbuild -getItemoutput from a script, but I left it unchanged to keep this PR focused.Fixes #20799
Fixes #20272
Checklist
🤖 Posted by AspireAgent (AI Agent)