Skip to content

Commit 036a909

Browse files
committed
Fixed issue where feed dependencies would be replaced by transitive dependencies.
1 parent 41bbc2d commit 036a909

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static bool TryWriteFiles(
4646
// We always save the Versions.g.props because it may not exist, and it may have been changed by the previous step.
4747
dependenciesOverrideFile.LocalBuildFile = propsFilePath;
4848

49-
if ( !dependenciesOverrideFile.TrySave( context, settings ) )
49+
if ( !dependenciesOverrideFile.TryWrite( context ) )
5050
{
5151
return false;
5252
}

src/PostSharp.Engineering.BuildTools/Dependencies/BaseFetchDependencyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected override bool ExecuteCore( BuildContext context, FetchDependenciesComm
3131
return false;
3232
}
3333

34-
if ( !dependenciesOverrideFile.TrySave( context, settings ) )
34+
if ( !dependenciesOverrideFile.TryWrite( context ) )
3535
{
3636
return false;
3737
}

src/PostSharp.Engineering.BuildTools/Dependencies/ConfigureDependenciesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected override bool ExecuteCore( BuildContext context, T settings )
111111
}
112112

113113
// Writing the version file.
114-
if ( !dependenciesOverrideFile.TrySave( context, settings ) )
114+
if ( !dependenciesOverrideFile.TryWrite( context ) )
115115
{
116116
return false;
117117
}

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ bool TryGetBuildId( out string? versionFile1, out ICiBuildSpec? ciBuildSpec )
292292
return true;
293293
}
294294

295-
public bool TrySave( BuildContext context, CommonCommandSettings settings )
295+
public bool TryWrite( BuildContext context )
296296
{
297297
var console = context.Console;
298298
var product = context.Product;
@@ -308,7 +308,7 @@ public bool TrySave( BuildContext context, CommonCommandSettings settings )
308308
dockerMountsWriter = File.CreateText( dockersMountsPath );
309309

310310
dockerMountsWriter.WriteLine(
311-
$"# File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(DependenciesConfigurationFile)}.{nameof(this.TrySave)}." );
311+
$"# File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(DependenciesConfigurationFile)}.{nameof(this.TryWrite)}." );
312312

313313
dockerMountsWriter.WriteLine();
314314
}
@@ -322,7 +322,7 @@ public bool TrySave( BuildContext context, CommonCommandSettings settings )
322322

323323
project.Add(
324324
new XComment(
325-
$"File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(DependenciesConfigurationFile)}.{nameof(this.TrySave)}." ) );
325+
$"File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(DependenciesConfigurationFile)}.{nameof(this.TryWrite)}." ) );
326326

327327
var requiredFiles = new List<string>();
328328

@@ -363,19 +363,24 @@ void AddImport( string file, bool required = true, string? label = null, bool ad
363363

364364
var itemGroup = new XElement( "ItemGroup" );
365365
project.Add( itemGroup );
366+
367+
var propertyGroup = new XElement( "PropertyGroup" );
368+
project.Add( propertyGroup );
369+
366370

367371
foreach ( var dependency in this.Dependencies.OrderBy( d => d.Key ) )
368372
{
369373
var ignoreDependency = false;
370374

371375
var dependencySource = dependency.Value;
376+
var dependencyDefinition = product.GetDependencyDefinition( dependency.Key );
372377

373378
var item = new XElement(
374379
"LocalDependencySource",
375380
new XAttribute( "Include", dependency.Key ),
376381
new XElement( "Kind", dependencySource.SourceKind ) );
377382

378-
void AddIfNotNull( string name, string? value )
383+
void AddMetadataToItemIfNotNull( string name, string? value )
379384
{
380385
if ( value != null )
381386
{
@@ -388,13 +393,13 @@ void WriteBuildServerSource()
388393
switch ( dependencySource.BuildServerSource )
389394
{
390395
case CiLatestBuildOfBranch branch:
391-
AddIfNotNull( "Branch", branch.Name );
396+
AddMetadataToItemIfNotNull( "Branch", branch.Name );
392397

393398
break;
394399

395400
case CiBuildId buildId:
396-
AddIfNotNull( "BuildNumber", buildId.BuildNumber.ToString( CultureInfo.InvariantCulture ) );
397-
AddIfNotNull( "CiBuildTypeId", buildId.BuildTypeId );
401+
AddMetadataToItemIfNotNull( "BuildNumber", buildId.BuildNumber.ToString( CultureInfo.InvariantCulture ) );
402+
AddMetadataToItemIfNotNull( "CiBuildTypeId", buildId.BuildTypeId );
398403

399404
break;
400405
}
@@ -405,8 +410,6 @@ void WriteBuildServerSource()
405410
case DependencySourceKind.BuildServer:
406411
case DependencySourceKind.RestoredDependency when !context.IsContinuousIntegrationBuild:
407412
{
408-
var dependencyDefinition = context.Product.ParametrizedDependencies.SingleOrDefault( p => p.Name == dependency.Key )?.Definition;
409-
410413
if ( dependencyDefinition == null
411414
&& !context.Product.ProductFamily.TryGetDependencyDefinition( dependency.Key, out dependencyDefinition ) )
412415
{
@@ -424,7 +427,7 @@ void WriteBuildServerSource()
424427

425428
WriteBuildServerSource();
426429

427-
AddIfNotNull( "VersionFile", versionFile );
430+
AddMetadataToItemIfNotNull( "VersionFile", versionFile );
428431
AddImport( versionFile );
429432
}
430433
}
@@ -433,7 +436,7 @@ void WriteBuildServerSource()
433436

434437
case DependencySourceKind.Local:
435438
{
436-
AddIfNotNull( "Path", dependencySource.LocalPath );
439+
AddMetadataToItemIfNotNull( "Path", dependencySource.LocalPath );
437440

438441
var importProjectFile = Path.GetFullPath(
439442
Path.Combine( dependencySource.GetResolvedLocalPath( context, dependency.Key ), dependency.Key + ".Import.props" ) );
@@ -461,7 +464,12 @@ void WriteBuildServerSource()
461464

462465
case DependencySourceKind.Feed:
463466
{
464-
AddIfNotNull( "Version", dependencySource.Version );
467+
AddMetadataToItemIfNotNull( "Version", dependencySource.Version );
468+
469+
// We must also save a property with the version, and set it before the imports, otherwise
470+
// the imports will override the setting in case of shared transitive dependency.
471+
472+
propertyGroup.Add( new XElement( $"{dependencyDefinition.NameWithoutDot}Version", dependencySource.Version ) );
465473
}
466474

467475
break;
@@ -478,23 +486,21 @@ void WriteBuildServerSource()
478486
}
479487
}
480488

481-
var properties = new XElement( "PropertyGroup" );
482-
project.Add( properties );
483-
properties.Add( new XElement( "ProductFamily", context.Product.ProductFamily.Name ) );
484-
properties.Add( new XElement( "ProductFamilyVersion", context.Product.ProductFamily.Version ) );
485-
properties.Add( new XElement( "BuildDate", $"$({context.Product.ProductNameWithoutDot}BuildDate)" ) );
489+
propertyGroup.Add( new XElement( "ProductFamily", context.Product.ProductFamily.Name ) );
490+
propertyGroup.Add( new XElement( "ProductFamilyVersion", context.Product.ProductFamily.Version ) );
491+
propertyGroup.Add( new XElement( "BuildDate", $"$({context.Product.ProductNameWithoutDot}BuildDate)" ) );
486492

487493
// The following properties are NOT related to dependencies. They are put here (instead of in a separate file) for convenience.
488-
properties.Add( new XElement( "PostSharpEngineeringExePath", context.Product.BuildExePath ) );
489-
properties.Add( new XElement( "PostSharpEngineeringDataDirectory", PathHelper.GetEngineeringDataDirectory() ) );
494+
propertyGroup.Add( new XElement( "PostSharpEngineeringExePath", context.Product.BuildExePath ) );
495+
propertyGroup.Add( new XElement( "PostSharpEngineeringDataDirectory", PathHelper.GetEngineeringDataDirectory() ) );
490496

491497
if ( product.MSBuildVersion != null )
492498
{
493499
var msbuild = MSBuildHelper.FindMSBuildExe( context );
494500

495501
if ( msbuild != null )
496502
{
497-
properties.Add( new XElement( "MSBuildExePath", "\"" + msbuild + "\"" ) );
503+
propertyGroup.Add( new XElement( "MSBuildExePath", "\"" + msbuild + "\"" ) );
498504
}
499505
}
500506

src/PostSharp.Engineering.BuildTools/Dependencies/UpdateEngineeringCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ protected override bool ExecuteCore( BuildContext context, CommonCommandSettings
122122
console.WriteSuccess( "Engineering successfully updated." );
123123

124124
// Generate scripts.
125-
if ( !GenerateScriptsCommand.Execute( context, settings ) )
126-
{
127-
return false;
128-
}
125+
console.WriteWarning( "Now run `./Build.ps1 generate-scripts` with this new version." );
129126

130127
return true;
131128
}

0 commit comments

Comments
 (0)