Skip to content

Embed test NuGet.Config files in binlogs - #6916

Merged
mthalman merged 9 commits into
dotnet:mainfrom
mthalman:dev/mthalman/issue5350
Jun 11, 2026
Merged

mthalman merged 9 commits into
dotnet:mainfrom
mthalman:dev/mthalman/issue5350

Conversation

@mthalman

Copy link
Copy Markdown
Member

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.

Fixes dotnet/source-build#5350

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]>
Copilot AI review requested due to automatic review settings May 29, 2026 20:27
@mthalman
mthalman requested review from a team as code owners May 29, 2026 20:27

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 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.targets assets 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 RestoreConfigFile config 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]>

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

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]>

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@mmitche

mmitche commented Jun 1, 2026

Copy link
Copy Markdown
Member

@mthalman Please verify that the NuGet.config files don't contain plaintext secrets when building internally.

@dotnet-policy-service
dotnet-policy-service Bot requested review from a team June 2, 2026 20:09
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
mthalman force-pushed the dev/mthalman/issue5350 branch from 4f25016 to c24aa27 Compare June 2, 2026 20:11
@mthalman

mthalman commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@mthalman Please verify that the NuGet.config files don't contain plaintext secrets when building internally.

Fixed in c24aa27

@mthalman
mthalman removed request for a team June 2, 2026 20:12
@mthalman

mthalman commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@dotnet/source-build - Please review

@ellahathaway ellahathaway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted 1 issue: unquoted /p: paths can break argument parsing on space-containing paths.

@ellahathaway ellahathaway left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit comment but otherwise LGTM

mthalman and others added 2 commits June 10, 2026 09:31
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]>

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

mthalman and others added 2 commits June 10, 2026 09:55
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]>
@mthalman
mthalman merged commit 50e862b into dotnet:main Jun 11, 2026
11 checks passed
@mthalman
mthalman deleted the dev/mthalman/issue5350 branch June 11, 2026 17:17
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.

Capture scenario test nuget.configs in the test project binlogs

4 participants