From 6812ed9fb87fbba996606efed736b6fb592e298d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 May 2026 14:08:53 +0000 Subject: [PATCH] Fix package source mapping logic in XSAddNugetSource.prgx (ticket #1915) Agent-Logs-Url: https://github.com/X-Sharp/XSharpPublic/sessions/8428819e-b1b2-4ad3-8c64-2c054715861d Co-authored-by: RobertvanderHulst <14240939+RobertvanderHulst@users.noreply.github.com> --- src/Runtime/Nuget/XSAddNugetSource.prgx | 41 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Runtime/Nuget/XSAddNugetSource.prgx b/src/Runtime/Nuget/XSAddNugetSource.prgx index c5a8996c64..c8eb5a5c14 100644 --- a/src/Runtime/Nuget/XSAddNugetSource.prgx +++ b/src/Runtime/Nuget/XSAddNugetSource.prgx @@ -26,20 +26,18 @@ if packageSources == null endif // Search "XSharp Offline Packages" and Add if missing GetSetPackageSource( packageSources, xsharpOffLine, sourceUrl ) -// Get the SourceMapping to "XSharp Offline Packages" ? -GetSetSourceMapping( configElement, xsharpOffLine, "XSharp.*" ) -// Is Nuget.org already in the list of package sources, if so add the SourceMapping to Nuget.org -IF SearchPackageSource(packageSources, "nuget.org") - GetSetSourceMapping( configElement, "nuget.org", "*" ) +// Handle source mappings based on whether mappings already exist +VAR existingMappings := configElement:Element("packageSourceMapping") +IF existingMappings != null + // Mappings exist: only update or add "XSharp.*" -> XSharp Offline Packages + GetSetSourceMapping( configElement, xsharpOffLine, "XSharp.*" ) ELSE - VAR sourceList := GetPackageSourceList(packageSources) - // No Nuget,and more than XSharp Offline Packages - // You might filter/choose your sources. - IF sourceList:Count == 1 - // Only XSharp Offline Packages, add Nuget.org as well + // No mappings: create "*" -> nuget.org and "XSharp.*" -> XSharp Offline Packages + IF !SearchPackageSource(packageSources, "nuget.org") GetSetPackageSource( packageSources, "nuget.org", "https://api.nuget.org/v3/index.json" ) - GetSetSourceMapping( configElement, "nuget.org", "*" ) ENDIF + GetSetSourceMapping( configElement, "nuget.org", "*" ) + GetSetSourceMapping( configElement, xsharpOffLine, "XSharp.*" ) ENDIF doc:Save(nugetConfigPath) @@ -76,16 +74,29 @@ if packageSourceMapping == null packageSourceMapping := XElement{"packageSourceMapping"} configElement:Add(packageSourceMapping) endif -VAR found := false -foreach elt as XElement in packageSourceMapping:Elements() +VAR sourceElement := null +foreach elt as XElement in packageSourceMapping:Elements() if elt:Attribute("key")?:Value == source - found := true + sourceElement := elt exit endif next -if !found +if sourceElement == null + // Source not found: add new packageSource element with the pattern VAR packageSource := XElement{"packageSource", XAttribute{"key", source}, XElement{"package", XAttribute{"pattern", pattern}}} packageSourceMapping:Add(packageSource) +else + // Source found: ensure the pattern is present + VAR patternFound := false + foreach pkg as XElement in sourceElement:Elements("package") + if pkg:Attribute("pattern")?:Value == pattern + patternFound := true + exit + endif + next + if !patternFound + sourceElement:Add(XElement{"package", XAttribute{"pattern", pattern}}) + endif endif