Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 10, 2025

Problem

The script eng/common/SetupNugetSources.sh was writing invalid XML comments when re-enabling disabled darc-int feeds in NuGet.Config files. When a disabled feed entry was already commented out, the script would create nested XML comments like:

<!-- <!-- Reenabled for build : darc-int-dotnet-runtime-12345 --> -->

This is not valid XML according to the XML specification (nested comments are not allowed), which causes NuGet to fail with parsing errors.

Root Cause

The script was replacing disabled entries with a comment:

local NewDisableValue="<!-- Reenabled for build : $PackageSourceName -->"
sed -i.bak "s|$OldDisableValue|$NewDisableValue|" "$ConfigFile"

This approach had two issues:

  1. It created nested comments when the entry was already commented out
  2. Feed names with double hyphens (--) could create invalid comment sequences like -->

Solution

Changed the script to simply delete the disabled entry line entirely, without adding any comment:

sed -i.bak "/<add key=\"$PackageSourceName\" value=\"true\" \/>/d" "$ConfigFile"

This approach:

  • ✅ Prevents nested XML comments
  • ✅ Avoids issues with special characters in feed names
  • ✅ Makes the bash script consistent with the PowerShell version (which already just removes entries)
  • ✅ Simplifies the code and eliminates the root cause

Testing

Added a new test ConfigWithCommentedOutDisabledDarcIntFeeds_RemovesEntriesAndProducesValidXml that specifically validates:

  • The script handles commented-out disabled entries correctly
  • The resulting XML is valid (can be parsed without errors)
  • No comment remnants are left in the file

All 26 tests pass, including manual verification with various edge cases (mixed disabled feeds, multiple darc-int feeds, special characters in feed names).

Fixes dotnet/source-build#5349

Original prompt

This section details on the original issue you should resolve

<issue_title>SetupNugetSources.sh writes invalid XML comments when re-enabling commented-out darc-int feeds</issue_title>
<issue_description>See dotnet/source-build#5349

The script eng/common/SetupNugetSources.sh writes invalid XML comments like:

<!-- <!-- Reenabled for build : <source> --> -->

when re-enabling disabled darc-int feeds in NuGet.Config that are already commented out. This is not valid XML and causes NuGet errors.

The script should be updated to only write single-layer XML comments (e.g., <!-- Reenabled for build : <source> -->), and avoid double hyphens or trailing hyphens in comments.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@mmitche The script should just not write out any comments for this, I think.

Fixes #16187


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: mmitche <8725170+mmitche@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid XML comments in SetupNugetSources.sh Fix SetupNugetSources.sh to avoid creating invalid XML comments when re-enabling disabled feeds Oct 10, 2025
Copilot AI requested a review from mmitche October 10, 2025 20:48
Copilot finished work on behalf of mmitche October 10, 2025 20:48
@mmitche mmitche marked this pull request as ready for review October 10, 2025 20:54
@akoeplinger akoeplinger enabled auto-merge (squash) October 11, 2025 16:39
@akoeplinger akoeplinger merged commit 872d3d0 into main Oct 13, 2025
10 checks passed
@akoeplinger akoeplinger deleted the copilot/fix-invalid-xml-comments branch October 13, 2025 11:32
@mmitche
Copy link
Member

mmitche commented Oct 13, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/arcade/actions/runs/18472466006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants