Skip to content

Commit ef19196

Browse files
committed
Improved error message, formatting of AutoUpdatedVersions.g.props.
1 parent b7092a3 commit ef19196

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/PostSharp.Engineering.BuildTools/Build/Files/AutoUpdatedVersionsFile.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/PostSharp.Engineering.BuildTools/Dependencies/Model/DependenciesConfigurationFile.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ void WriteBuildServerSource()
413413

414414
if ( versionFile == null )
415415
{
416-
throw new InvalidOperationException( "The VersionFile property of dependencies should be set." );
416+
throw new InvalidOperationException( $"'{this.FilePath}': The VersionFile property of dependency '{dependency.Key}' is not set." );
417417
}
418418

419419
WriteBuildServerSource();
@@ -458,8 +458,13 @@ void WriteBuildServerSource()
458458

459459
// We must also save a property with the version, and set it before the imports, otherwise
460460
// the imports will override the setting in case of shared transitive dependency.
461+
// Only add the version property if we have an actual version. An empty version property
462+
// would incorrectly override a version set elsewhere.
461463

462-
propertyGroup.Add( new XElement( $"{dependencyDefinition.NameWithoutDot}Version", dependencySource.Version ) );
464+
if ( !string.IsNullOrEmpty( dependencySource.Version ) )
465+
{
466+
propertyGroup.Add( new XElement( $"{dependencyDefinition.NameWithoutDot}Version", dependencySource.Version ) );
467+
}
463468
}
464469

465470
break;

0 commit comments

Comments
 (0)