@@ -97,7 +97,7 @@ public static bool TryWrite(
9797
9898 if ( File . Exists ( thisAutoUpdatedVersionsFilePath ) )
9999 {
100- thisAutoUpdatedVersionsDocument = XDocument . Load ( thisAutoUpdatedVersionsFilePath , LoadOptions . PreserveWhitespace ) ;
100+ thisAutoUpdatedVersionsDocument = XDocument . Load ( thisAutoUpdatedVersionsFilePath ) ;
101101 thisAutoUpdatedVersionsPropertyGroupElement = thisAutoUpdatedVersionsDocument . Root ! . Element ( "PropertyGroup" ) ! ;
102102 }
103103 else
@@ -176,6 +176,7 @@ public static bool TryWrite(
176176 thisAutoUpdatedVersionsPropertyGroupElement . Add ( versionElement ) ;
177177 }
178178
179+ versionElement . SetAttributeValue ( "Condition" , $ "'$({ versionElementName } )' == ''" ) ;
179180 versionElement . Value = dependencyReleasedVersion ;
180181 hasChanges = true ;
181182 hasDependenciesChanges = true ;
@@ -244,18 +245,15 @@ public static bool TryWrite(
244245 thisMainVersionElement . Value = versionComponents . MainVersion ;
245246 }
246247
247- // Write changes.
248- if ( hasChanges )
248+ // Write changes (always try to write to handle formatting and condition changes) .
249+ if ( ! dry )
249250 {
250- if ( ! dry )
251- {
252- hasChanges = TextFileHelper . WriteIfDifferent ( thisAutoUpdatedVersionsFilePath , thisAutoUpdatedVersionsDocument , context ) ;
253- }
254- else
255- {
256- context . Console . WriteMessage ( $ "New content for '{ thisAutoUpdatedVersionsFilePath } ':" ) ;
257- context . Console . WriteMessage ( thisAutoUpdatedVersionsDocument . ToNiceString ( ) ) ;
258- }
251+ hasChanges = TextFileHelper . WriteIfDifferent ( thisAutoUpdatedVersionsFilePath , thisAutoUpdatedVersionsDocument , context ) ;
252+ }
253+ else if ( hasChanges )
254+ {
255+ context . Console . WriteMessage ( $ "New content for '{ thisAutoUpdatedVersionsFilePath } ':" ) ;
256+ context . Console . WriteMessage ( thisAutoUpdatedVersionsDocument . ToNiceString ( ) ) ;
259257 }
260258
261259 packageVersion = versionComponents . PackageVersion ;
0 commit comments