Repository navigation
Embed test NuGet.Config files in binlogs - #6916
Merged
Merged
Conversation
When a scenario test's restore fails because the NuGet.Config it uses is malformed (e.g. invalid XML), the binlog uploaded as a CI artifact didn't contain the offending config, making the failure hard to diagnose. Use MSBuild's standard @(EmbedInBinlog) item-group convention to embed the NuGet.Config into every binlog produced by the source-build and scenario tests: * test/Microsoft.DotNet.SourceBuild.Tests: embed the dynamically-generated projects-<timestamp>/NuGet.Config that DotNetHelper creates. * src/scenario-tests SdkTemplateTests: embed the file pointed to by the RestoreConfigFile env var when set. The embedding is injected via /p:CustomAfterMicrosoftCommonTargets pointing at a small targets file that adds the config path to @(EmbedInBinlog), so it runs inside the generated test project's MSBuild evaluation rather than the harness project. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR embeds the NuGet.Config files used by source-build and scenario/template tests into produced MSBuild binlogs, improving diagnosis when restore fails due to malformed or unexpected config content.
Changes:
- Adds
EmbedFileInBinlog.targetsassets that include a configured file path in@(EmbedInBinlog). - Updates source-build test binlog arguments to embed the generated
NuGet.Config. - Updates SDK template scenario tests to copy the asset and embed the
RestoreConfigFileconfig when present.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
test/Microsoft.DotNet.SourceBuild.Tests/DotNetHelper.cs |
Exposes the generated NuGet.Config path and passes embedding properties with binlog options. |
test/Microsoft.DotNet.SourceBuild.Tests/assets/EmbedFileInBinlog.targets |
Adds the MSBuild item used to embed the configured file into binlogs. |
src/scenario-tests/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/Microsoft.DotNet.ScenarioTests.SdkTemplateTests.csproj |
Copies the new assets folder to test output. |
src/scenario-tests/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkHelper.cs |
Adds RestoreConfigFile-based embedding properties to scenario-test binlog arguments. |
src/scenario-tests/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/assets/EmbedFileInBinlog.targets |
Adds the MSBuild item used to embed the configured file into binlogs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Multi-targeting projects' outer build imports Microsoft.Common.CrossTargeting.targets rather than Microsoft.Common.targets, so CustomAfterMicrosoftCommonTargets is not honored there. A restore failure on a multi-TFM scenario test would happen during that outer build and the NuGet.Config wouldn't make it into the binlog. Also pass the same targets file via CustomAfterMicrosoftCommonCrossTargetingTargets so the @(EmbedInBinlog) item is added in both single-TFM and multi-TFM evaluations. Co-authored-by: Copilot <[email protected]>
The SDK default item glob already picks up assets\** as a None item. Adding <None Include="assets\**"> creates a duplicate that can trigger NETSDK1022. Use <None Update="assets\**"> to attach the CopyToOutputDirectory metadata to the existing default item instead. Co-authored-by: Copilot <[email protected]>
Member
|
@mthalman Please verify that the NuGet.config files don't contain plaintext secrets when building internally. |
Production NuGet.config files in CI can contain feed credentials in <packageSourceCredentials>. Embedding the file verbatim in a binlog would leak those credentials. Both helpers now write a sibling NuGet.Config.sanitized file with the credentials element replaced by a comment placeholder, and embed that file instead. Co-authored-by: Copilot <[email protected]>
mthalman
force-pushed
the
dev/mthalman/issue5350
branch
from
June 2, 2026 20:11
4f25016 to
c24aa27
Compare
Member
Author
Member
Author
|
@dotnet/source-build - Please review |
ellahathaway
reviewed
Jun 9, 2026
ellahathaway
left a comment
Member
There was a problem hiding this comment.
Posted 1 issue: unquoted /p: paths can break argument parsing on space-containing paths.
ellahathaway
reviewed
Jun 9, 2026
Both DotNetHelper.GetBinLogOption and DotNetSdkHelper.GetBinLogOption build a command line string that's passed to dotnet. The interpolated paths (EmbedFileInBinlogTargetsPath, NuGet.Config.sanitized) come from locations like Path.GetTempPath() and AppContext.BaseDirectory which can contain spaces on Windows or macOS agents. Without quoting, command line tokenization would split the property value and silently skip the intended Custom*Targets / EmbedFileInBinlogPath imports. Use the /p:"name=value" form which MSBuild accepts on both Windows and Unix shells. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
The non-greedy regex required a literal </packageSourceCredentials> closing tag to match. A malformed/truncated NuGet.Config missing the closing tag would fall through the regex unchanged, leaving the credentials in the embedded binlog. Mirror the fix already applied to test/Microsoft.DotNet.SourceBuild.Tests (commit 094766b) so the regex matches the closing tag or end-of-input. Co-authored-by: Copilot <[email protected]>
ellahathaway
approved these changes
Jun 11, 2026
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.
When a scenario test's restore fails because the
NuGet.Configit uses is malformed (e.g. invalid XML), the binlog uploaded as a CI artifact didn't contain the offending config, making the failure hard to diagnose.Use MSBuild's standard
@(EmbedInBinlog)item-group convention to embed theNuGet.Configinto every binlog produced by the source-build and scenario tests:test/Microsoft.DotNet.SourceBuild.Tests: embed the dynamically-generated projects-<timestamp>/NuGet.ConfigthatDotNetHelpercreates.src/scenario-tests SdkTemplateTests: embed the file pointed to by theRestoreConfigFileenv var when set.The embedding is injected via
/p:CustomAfterMicrosoftCommonTargetspointing at a small targets file that adds the config path to@(EmbedInBinlog), so it runs inside the generated test project's MSBuild evaluation rather than the harness project.Fixes dotnet/source-build#5350