src/Microsoft.DotNet.Darc/src/DarcLib/Helpers/GitFileManager.cs
/// <summary>
///     Update well-known version files.
/// </summary>
/// <param name="versionProps">Versions.props xml document</param>
/// <param name="token">Global.json document</param>
/// <param name="itemToUpdate">Item that needs an update.</param>
/// <remarks>
///     TODO: https://github.com/dotnet/arcade/issues/1095
/// </remarks>
Update well-known version files.
Update well - known version files .
private void UpdateVersionFiles(XmlDocument versionProps, JToken token, DependencyDetail itemToUpdate)
        {
            string versionElementName = VersionFiles.GetVersionPropsPackageVersionElementName(itemToUpdate.Name);
            string alternateVersionElementName = VersionFiles.GetVersionPropsAlternatePackageVersionElementName(itemToUpdate.Name);
            XmlNode packageVersionNode = versionProps.DocumentElement.SelectSingleNode(
                $"//*[translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=" +
                $"'{versionElementName.ToLower()}']");
            string foundElementName = versionElementName;
            if (packageVersionNode == null)
            {
                packageVersionNode = versionProps.DocumentElement.SelectSingleNode(
                    $"//*[translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=" +
                    $"'{alternateVersionElementName.ToLower()}']");
                foundElementName = alternateVersionElementName;
            }
            if (packageVersionNode != null)
            {
                packageVersionNode.InnerText = itemToUpdate.Version;
                if (packageVersionNode.LocalName != foundElementName)
                {
                    {
                        XmlNode parentNode = packageVersionNode.ParentNode;
                        XmlNode newPackageVersionElement = versionProps.CreateElement(
                            foundElementName, 
                            versionProps.DocumentElement.NamespaceURI);
                        newPackageVersionElement.InnerText = itemToUpdate.Version;
                        parentNode.ReplaceChild(newPackageVersionElement, packageVersionNode);
                    }
                    {
                        string packageNameElementName = VersionFiles.GetVersionPropsPackageElementName(itemToUpdate.Name);
                        XmlNode packageNameNode = versionProps.DocumentElement.SelectSingleNode(
                            $"//*[translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=" +
                            $"'{packageNameElementName.ToLower()}']");
                        if (packageNameNode != null)
                        {
                            XmlNode parentNode = packageNameNode.ParentNode;
                            XmlNode newPackageNameElement = versionProps.CreateElement(
                                packageNameElementName, 
                                versionProps.DocumentElement.NamespaceURI);
                            newPackageNameElement.InnerText = itemToUpdate.Name;
                            parentNode.ReplaceChild(newPackageNameElement, packageNameNode);
                        }
                    }
                }
            }
            else
            {
                UpdateVersionGlobalJson(itemToUpdate, token);
            }
        }
private void UpdateVersionFiles ( XmlDocument versionProps , JToken token , DependencyDetail itemToUpdate ) { string versionElementName = VersionFiles . GetVersionPropsPackageVersionElementName ( itemToUpdate . Name ) ; string alternateVersionElementName = VersionFiles . GetVersionPropsAlternatePackageVersionElementName ( itemToUpdate . Name ) ; XmlNode packageVersionNode = versionProps . DocumentElement . SelectSingleNode ( $" //*[translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')= " + $" ' { versionElementName . ToLower ( ) } '] " ) ; string foundElementName = versionElementName ; if ( packageVersionNode == null ) { packageVersionNode = versionProps . DocumentElement . SelectSingleNode ( $" //*[translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')= " + $" ' { alternateVersionElementName . ToLower ( ) } '] " ) ; foundElementName = alternateVersionElementName ; } if ( packageVersionNode != null ) { packageVersionNode . InnerText = itemToUpdate . Version ; if ( packageVersionNode . LocalName != foundElementName ) { { XmlNode parentNode = packageVersionNode . ParentNode ; XmlNode newPackageVersionElement = versionProps . CreateElement ( foundElementName , versionProps . DocumentElement . NamespaceURI ) ; newPackageVersionElement . InnerText = itemToUpdate . Version ; parentNode . ReplaceChild ( newPackageVersionElement , packageVersionNode ) ; } { string packageNameElementName = VersionFiles . GetVersionPropsPackageElementName ( itemToUpdate . Name ) ; XmlNode packageNameNode = versionProps . DocumentElement . SelectSingleNode ( $" //*[translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')= " + $" ' { packageNameElementName . ToLower ( ) } '] " ) ; if ( packageNameNode != null ) { XmlNode parentNode = packageNameNode . ParentNode ; XmlNode newPackageNameElement = versionProps . CreateElement ( packageNameElementName , versionProps . DocumentElement . NamespaceURI ) ; newPackageNameElement . InnerText = itemToUpdate . Name ; parentNode . ReplaceChild ( newPackageNameElement , packageNameNode ) ; } } } } else { UpdateVersionGlobalJson ( itemToUpdate , token ) ; } }
Update well-known version files.
Update well - known version files .
// Select nodes case insensitively, then update the name. // Find alternate names // If the node name was updated, then create a new node with the new name, unlink this node // and create a new one in the same location. // Update the package name element too.
versionProps
XmlDocument
Versions.props xml document
Versions . props xml document
token
JToken
None
itemToUpdate
DependencyDetail
Item that needs an update.
Item that needs an update .
remarks
None