@@ -106,6 +106,15 @@ private async Task ConvertAsync(string projectFilePath)
106106 packageReferenceVersionElement . SetAttributeValue ( "Version" , versionElement . Value ) ;
107107 versionElement . Remove ( ) ;
108108
109+ // remove empty child nodes within the <PackageReference>
110+ var childNodes = packageReferenceVersionElement . Nodes ( )
111+ . OfType < XText > ( )
112+ . Where ( x => string . IsNullOrWhiteSpace ( x . Value ) ) ;
113+ foreach ( var node in childNodes )
114+ {
115+ node . Remove ( ) ;
116+ }
117+
109118 // Check if the PackageReference is empty and set it to self-closing if so
110119 if ( ! packageReferenceVersionElement . HasElements )
111120 {
@@ -138,27 +147,6 @@ private async Task ConvertAsync(string projectFilePath)
138147 this . fileService . RemoveReadOnlyAttribute ( projectFilePath ) ;
139148 }
140149
141- // remove empty lines within <PackageReference> elements
142- // Select all <PackageReference> elements
143- var packageReferenceElements = document . XPathSelectElements ( "//PackageReference" ) ;
144-
145- foreach ( var packageReferenceElement in packageReferenceElements )
146- {
147- // Get all the child nodes of the <PackageReference>
148- var childNodes = packageReferenceElement . Nodes ( ) ;
149-
150- // Iterate through the child nodes
151- foreach ( var node in childNodes )
152- {
153- // Check if the node is a text node and contains only whitespace
154- if ( node is XText textNode && string . IsNullOrWhiteSpace ( textNode . Value ) )
155- {
156- // Remove the empty line
157- textNode . Remove ( ) ;
158- }
159- }
160- }
161-
162150 var settings = new XmlWriterSettings
163151 {
164152 OmitXmlDeclaration = document . Declaration == null , // Preserve the XML declaration if it exists.
0 commit comments