@joebigelow / wix-1 / commits / 2f1a8d6c

Generate metadata needed to populate update feed

Step towards completing 5367

Rob Mensching committed Aug 8, 2022 at 10:43 UTC 2f1a8d6caa50640925bf634062121391c450a5ed
10 files changed +224 -11
src/Directory.wixproj.props
+2 -1
@@ -3,7 +3,8 @@
3
4 <Project>
5 <PropertyGroup>
6 - <!-- TODO: changing the .wixpdb folder does not actually work until issue #6857 is resolved -->
6 + <!-- TODO: changing the .wixpdb folder does not actually work until issue #6857 is resolved
7 <PdbOutputDir>$(PdbsFolder)</PdbOutputDir>
8 + -->
9 </PropertyGroup>
10 </Project>
src/Directory.wixproj.targets
+1 -1
@@ -8,7 +8,7 @@
8 <PropertyGroup>
9 <DefineConstants>
10 $(DefineConstants);
11 - SetupVersion=$(FileVersion);
11 + SetupVersion=$(PackageVersion);
12 SetupMajorMinorVersion=$(GitBaseVersionMajor).$(GitBaseVersionMinor);
13 </DefineConstants>
14 </PropertyGroup>
src/internal/SetBuildNumber/Directory.Packages.props.pp
+1
@@ -47,6 +47,7 @@
47 <PackageVersion Include="System.Reflection.Metadata" Version="1.6.0" />
48 <PackageVersion Include="System.Security.Principal.Windows" Version="4.7.0" />
49 <PackageVersion Include="System.Text.Encoding.CodePages" Version="4.6.0" />
50 + <PackageVersion Include="System.Text.Json" Version="4.6.0" />
51
52 <PackageVersion Include="Microsoft.AspNetCore.Owin" Version="3.1.13" />
53 <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
src/setup/Directory.Build.props
-4
@@ -7,8 +7,4 @@
7 </PropertyGroup>
8
9 <Import Project="..\Directory.Build.props" />
10 -
11 - <PropertyGroup>
12 - <PublishRoot>$(OutputPath)publish\</PublishRoot>
13 - </PropertyGroup>
10 </Project>
src/setup/MetadataTask/GenerateMetadata.cs new
+113
@@ -0,0 +1,113 @@
1 +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2 +
3 +namespace WixToolset.Tasks
4 +{
5 + using System;
6 + using System.Collections.Generic;
7 + using System.IO;
8 + using System.Linq;
9 + using System.Security.Cryptography;
10 + using System.Text.Json;
11 + using System.Text.Json.Serialization;
12 + using Microsoft.Build.Framework;
13 + using Microsoft.Build.Utilities;
14 + using WixToolset.Data;
15 + using WixToolset.Data.Symbols;
16 +
17 + public class GenerateMetadata : Task
18 + {
19 + private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions
20 + {
21 + PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
22 + IgnoreNullValues = true,
23 + WriteIndented = true,
24 + Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
25 + };
26 +
27 + [Required]
28 + public string TargetFile { get; set; }
29 +
30 + [Required]
31 + public string WixpdbFile { get; set; }
32 +
33 + public override bool Execute()
34 + {
35 + var intermediate = Intermediate.Load(this.WixpdbFile);
36 +
37 + var section = intermediate.Sections.Single();
38 +
39 + if (section.Type != SectionType.Bundle)
40 + {
41 + return false;
42 + }
43 +
44 + (var metadata, var sourceLineNumber) = this.GetBundleMetadata(section);
45 +
46 + if (metadata != null)
47 + {
48 + this.PopulateFileInfo(metadata);
49 +
50 + this.SaveMetadata(metadata, sourceLineNumber);
51 + }
52 +
53 + return true;
54 + }
55 +
56 + private (Metadata, SourceLineNumber) GetBundleMetadata(IntermediateSection section)
57 + {
58 + var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single();
59 +
60 + var metadata = new Metadata
61 + {
62 + Type = MetadataType.Burn,
63 + Name = bundleSymbol.Name,
64 + Version = bundleSymbol.Version,
65 + Publisher = bundleSymbol.Manufacturer,
66 + Description = "Installation for " + bundleSymbol.Name,
67 + SupportUrl = bundleSymbol.HelpUrl,
68 + BundleCode = bundleSymbol.BundleId,
69 + UpgradeCode = bundleSymbol.UpgradeCode,
70 + AboutUrl = bundleSymbol.AboutUrl,
71 + Architecture = PlatformToArchitecture(bundleSymbol.Platform),
72 + };
73 +
74 + return (metadata, bundleSymbol.SourceLineNumbers);
75 + }
76 +
77 + private void PopulateFileInfo(Metadata metadata)
78 + {
79 + var fi = new FileInfo(this.TargetFile);
80 +
81 + using (var sha256 = SHA256.Create())
82 + using (var stream = fi.OpenRead())
83 + {
84 + var hash = sha256.ComputeHash(stream);
85 +
86 + metadata.File = fi.Name;
87 + metadata.Created = fi.CreationTimeUtc.ToString("O");
88 + metadata.Size = fi.Length;
89 + metadata.Sha256 = BitConverter.ToString(hash).Replace("-", String.Empty);
90 + }
91 + }
92 +
93 + private void SaveMetadata(Metadata metadata, SourceLineNumber sourceLineNumber)
94 + {
95 + var metadataFilePath = Path.ChangeExtension(this.TargetFile, "metadata.json");
96 +
97 + var json = JsonSerializer.Serialize(metadata, SerializerOptions);
98 +
99 + File.WriteAllText(metadataFilePath, json);
100 + }
101 +
102 + private static ArchitectureType PlatformToArchitecture(Platform platform)
103 + {
104 + switch (platform)
105 + {
106 + case Platform.X86: return ArchitectureType.X86;
107 + case Platform.X64: return ArchitectureType.X86;
108 + case Platform.ARM64: return ArchitectureType.X86;
109 + default: throw new ArgumentException($"Unknown platform {platform}");
110 + }
111 + }
112 + }
113 +}
src/setup/MetadataTask/Metadata.cs new
+78
@@ -0,0 +1,78 @@
1 +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2 +
3 +namespace WixToolset.Tasks
4 +{
5 + public enum MetadataType
6 + {
7 + Unknown,
8 + Burn,
9 + Msi,
10 + }
11 +
12 + public enum ArchitectureType
13 + {
14 + Unknown,
15 + Arm64,
16 + X64,
17 + X86,
18 + }
19 +
20 + //{
21 + // "id": [PackageSymbolId] | [BundleSymbolId],
22 + // "type": "msi" | "burn"
23 + // "name": [ProductName] | [BundleName]
24 + // "locale": [ProductLanguage] | [BundleLanguage]
25 + // "publisher": [Manufacturer]
26 + // "aboutUrl": [ARPURLINFOABOUT] | [AboutUrl]
27 + // "supportUrl": [ARPHELPLINK] | [SupportUrl]
28 + // "description": [ARPCOMMENTS] | "Installation for" + [BundleName]
29 + // "license": [ProductLicense] | [BundleLicense]
30 + // "architecture": "x86" | "x64" | "arm64"
31 + // "size": ####
32 + // "sha256": hex,
33 + // "file": <filename>
34 + // "created": <ISO timestamp>
35 + // "productCode": [ProductCode]
36 + // "bundleCode": [BundleId]
37 + // "upgradeCode": [UpgradeCode]
38 + //}
39 +
40 + public class Metadata
41 + {
42 + public string Id { get; set; }
43 +
44 + public MetadataType Type { get; set; }
45 +
46 + public string Name { get; set; }
47 +
48 + public string Version { get; set; }
49 +
50 + public string Locale { get; set; }
51 +
52 + public string Publisher { get; set; }
53 +
54 + public string AboutUrl { get; set; }
55 +
56 + public string SupportUrl { get; set; }
57 +
58 + public string Description { get; set; }
59 +
60 + public string License { get; set; }
61 +
62 + public ArchitectureType Architecture { get; set; }
63 +
64 + public string File { get; set; }
65 +
66 + public long Size { get; set; }
67 +
68 + public string Sha256 { get; set; }
69 +
70 + public string Created { get; set; }
71 +
72 + public string ProductCode { get; set; }
73 +
74 + public string BundleCode { get; set; }
75 +
76 + public string UpgradeCode { get; set; }
77 + }
78 +}
src/setup/MetadataTask/MetadataTask.csproj new
+14
@@ -0,0 +1,14 @@
1 +<Project Sdk="Microsoft.NET.Sdk">
2 + <PropertyGroup>
3 + <TargetFramework>net472</TargetFramework>
4 + <DebugType>embedded</DebugType>
5 + <!-- https://github.com/Microsoft/msbuild/issues/2360 -->
6 + <PlatformTarget>AnyCPU</PlatformTarget>
7 + </PropertyGroup>
8 +
9 + <ItemGroup>
10 + <PackageReference Include="Microsoft.Build.Tasks.Core" />
11 + <PackageReference Include="System.Text.Json" />
12 + <PackageReference Include="WixToolset.Data" />
13 + </ItemGroup>
14 +</Project>
src/setup/WixAdditionalTools/WixAdditionalTools.wixproj
+5
@@ -14,4 +14,9 @@
14 <PackageReference Include="GitInfo" PrivateAssets="All" />
15 </ItemGroup>
16
17 + <UsingTask TaskName="GenerateMetadata" AssemblyFile="$(BaseOutputPath)$(Configuration)\net472\MetadataTask.dll" />
18 +
19 + <Target Name="GenerateMetadata" AfterTargets="AfterBuild">
20 + <GenerateMetadata TargetFile="$(TargetPath)" WixpdbFile="$(TargetPdbPath)" />
21 + </Target>
22 </Project>
src/setup/setup.cmd
+2
@@ -17,6 +17,8 @@
17 @echo Building setup %_C%
18
19 :: Build
20 +msbuild -Restore MetadataTask\MetadataTask.csproj -p:Configuration=%_C% -nologo -m -warnaserror -bl:%_L%\setup_task.binlog || exit /b
21 +
22 msbuild -Restore setup.sln -p:Configuration=%_C% -nologo -m -warnaserror -bl:%_L%\setup_build.binlog || exit /b
23
24 :: Publish
src/setup/setup.sln
+8 -5
@@ -1,7 +1,7 @@
1 
2 Microsoft Visual Studio Solution File, Format Version 12.00
3 -# Visual Studio Version 16
4 -VisualStudioVersion = 16.0.30114.105
3 +# Visual Studio Version 17
4 +VisualStudioVersion = 17.2.32630.192
5 MinimumVisualStudioVersion = 10.0.40219.1
6 Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "ThmViewerPackage", "ThmViewerPackage\ThmViewerPackage.wixproj", "{F8C12838-DEC5-4CA5-97A8-DFE2247564C5}"
7 EndProject
@@ -12,9 +12,6 @@ Global
12 Debug|Any CPU = Debug|Any CPU
13 Release|Any CPU = Release|Any CPU
14 EndGlobalSection
15 - GlobalSection(SolutionProperties) = preSolution
16 - HideSolutionNode = FALSE
17 - EndGlobalSection
15 GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 {F8C12838-DEC5-4CA5-97A8-DFE2247564C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 {F8C12838-DEC5-4CA5-97A8-DFE2247564C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -25,4 +22,10 @@ Global
22 {59FF3AD3-339A-4048-9F0B-504EE74BC4AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 {59FF3AD3-339A-4048-9F0B-504EE74BC4AF}.Release|Any CPU.Build.0 = Release|Any CPU
24 EndGlobalSection
25 + GlobalSection(SolutionProperties) = preSolution
26 + HideSolutionNode = FALSE
27 + EndGlobalSection
28 + GlobalSection(ExtensibilityGlobals) = postSolution
29 + SolutionGuid = {1E2BB345-987B-4108-8EB9-10D703F02EFC}
30 + EndGlobalSection
31 EndGlobal