Prebuilt report fix (#15329)

This commit is contained in:
Matt Mitchell 2023-01-24 11:57:16 -08:00 committed by GitHub
parent 154f9b87ce
commit c9bfab9a6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 23 deletions

View file

@ -195,13 +195,14 @@ namespace Microsoft.DotNet.SourceBuild.Tasks.UsageReport
// Get the embedded creation time if possible: the file's original metadata may // Get the embedded creation time if possible: the file's original metadata may
// have been destroyed by copying, zipping, etc. // have been destroyed by copying, zipping, etc.
string creationTime = snapshot.Xml string creationTime = snapshot.Xml
// Get the second PropertyGroup. // Get all elements
.Elements().Skip(1).FirstOrDefault() .Elements()
// Get the creation time element. // Select all the subelements
?.Element(snapshot.Xml .SelectMany(e => e.Elements())
.GetDefaultNamespace() // Find all that match the creation time property name
.GetName(WritePackageVersionsProps.CreationTimePropertyName)) .Where(e => e.Name == snapshot.Xml.GetDefaultNamespace().GetName(WritePackageVersionsProps.CreationTimePropertyName))
?.Value; // There should be only one or zero
.SingleOrDefault()?.Value;
if (string.IsNullOrEmpty(creationTime)) if (string.IsNullOrEmpty(creationTime))
{ {
@ -279,7 +280,8 @@ namespace Microsoft.DotNet.SourceBuild.Tasks.UsageReport
public static PackageVersionPropsElement[] Parse(XElement xml) public static PackageVersionPropsElement[] Parse(XElement xml)
{ {
return xml return xml
// Get the single PropertyGroup // Get the first PropertyGroup. The second PropertyGroup is 'extra properties', and the third group is the creation time.
// Only select the first because the extra properties are not built packages.
.Elements() .Elements()
.First() .First()
// Get all *PackageVersion property elements. // Get all *PackageVersion property elements.

View file

@ -61,13 +61,6 @@ namespace Microsoft.DotNet.Build.Tasks
[Required] [Required]
public string OutputPath { get; set; } public string OutputPath { get; set; }
/// <summary>
/// Adds a second PropertyGroup to the output XML containing a property with the time of
/// creation in UTC DateTime Ticks. This can be used to track creation time in situations
/// where file metadata isn't reliable or preserved.
/// </summary>
public bool IncludeCreationTimeProperty { get; set; }
/// <summary> /// <summary>
/// Properties to add to the build output props, which may not exist as nupkgs. /// Properties to add to the build output props, which may not exist as nupkgs.
/// FOr example, this is used to pass the version of the CLI toolset archives. /// FOr example, this is used to pass the version of the CLI toolset archives.
@ -242,12 +235,9 @@ namespace Microsoft.DotNet.Build.Tasks
WriteExtraProperties(sw); WriteExtraProperties(sw);
WriteVersionEntries(sw, additionalAssetElementsToWrite, "additional assets"); WriteVersionEntries(sw, additionalAssetElementsToWrite, "additional assets");
if (IncludeCreationTimeProperty)
{
sw.WriteLine(@" <PropertyGroup>"); sw.WriteLine(@" <PropertyGroup>");
sw.WriteLine($@" <{CreationTimePropertyName}>{DateTime.UtcNow.Ticks}</{CreationTimePropertyName}>"); sw.WriteLine($@" <{CreationTimePropertyName}>{DateTime.UtcNow.Ticks}</{CreationTimePropertyName}>");
sw.WriteLine(@" </PropertyGroup>"); sw.WriteLine(@" </PropertyGroup>");
}
sw.WriteLine(@"</Project>"); sw.WriteLine(@"</Project>");
} }

View file

@ -602,7 +602,7 @@
Outputs="$(RepoCompletedSemaphorePath)WritePrebuiltUsageData.complete"> Outputs="$(RepoCompletedSemaphorePath)WritePrebuiltUsageData.complete">
<!-- Save the PVP snapshot of each build step to be evaluated while building the report. --> <!-- Save the PVP snapshot of each build step to be evaluated while building the report. -->
<ItemGroup> <ItemGroup>
<PackageVersionPropsSnapshotFiles Include="$(IntermediatePath)PackageVersions.props.pre.*.xml" /> <PackageVersionPropsSnapshotFiles Include="$(IntermediatePath)PackageVersions.*.Current.props" />
</ItemGroup> </ItemGroup>
<Copy SourceFiles="@(PackageVersionPropsSnapshotFiles)" DestinationFolder="$(PackageReportDir)snapshots/" /> <Copy SourceFiles="@(PackageVersionPropsSnapshotFiles)" DestinationFolder="$(PackageReportDir)snapshots/" />
@ -688,7 +688,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageVersionPropsSavedSnapshotFiles Include="$(PackageReportDir)snapshots/PackageVersions.props.pre.*.xml" /> <PackageVersionPropsSavedSnapshotFiles Include="$(PackageReportDir)snapshots/PackageVersions.*.Current.props" />
</ItemGroup> </ItemGroup>
<WriteUsageReports DataFile="$(PackageReportDataFile)" <WriteUsageReports DataFile="$(PackageReportDataFile)"