diff --git a/eng/update-dependencies/NuGetConfigUpdater.cs b/eng/update-dependencies/NuGetConfigUpdater.cs index 92981c0508..d9c21861b7 100644 --- a/eng/update-dependencies/NuGetConfigUpdater.cs +++ b/eng/update-dependencies/NuGetConfigUpdater.cs @@ -87,17 +87,17 @@ private void UpdatePackageSourceCredentials(string pkgSrcName, XElement configur XElement? pkgSourceCreds = configuration.Element("packageSourceCredentials"); if (_options.IsInternal) { - pkgSourceCreds?.Remove(); - - pkgSourceCreds = new XElement("packageSourceCredentials"); - configuration.Add(pkgSourceCreds); + pkgSourceCreds = GetOrCreateXObject( + pkgSourceCreds, + configuration, + () => new XElement("packageSourceCredentials")); - XElement pkgSrc = GetOrCreateXObject( + XElement pkgSrcCredsEntry = GetOrCreateXObject( pkgSourceCreds.Element(pkgSrcName), pkgSourceCreds, () => new XElement(pkgSrcName)); - UpdateAddElement(pkgSrc, "Username", "dotnet"); - UpdateAddElement(pkgSrc, "ClearTextPassword", "%NuGetFeedPassword%"); + UpdateAddElement(pkgSrcCredsEntry, "Username", "dotnet"); + UpdateAddElement(pkgSrcCredsEntry, "ClearTextPassword", "%NuGetFeedPassword%"); } else { @@ -115,8 +115,6 @@ private void UpdatePackageSources(string sdkVersion, string pkgSrcName, XElement configuration, () => new XElement("packageSources")); - RemoveAllInternalPackageSources(pkgSources); - string project = _options.DockerfileVersion != "3.1" ? "/internal" : string.Empty; UpdateAddElement(