Skip to content

Commit ddd78da

Browse files
committed
installer: auto-generate ProductId
- ensures MajorUpgrade - prevents multiple installations
1 parent da331be commit ddd78da

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Installer/Installer.wixproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@
2626
<OutputName>usbipd-win</OutputName>
2727
<DefineSolutionProperties>false</DefineSolutionProperties>
2828
<PublishDir>..\UsbIpServer\bin\publish</PublishDir>
29+
<!--
30+
This ensures that each x.y.z version has a different product, so every upgrade is a MajorUpgrade.
31+
It also ensures that 2 builds of the same x.y.z version will never be installed simultaneously.
32+
The alternative (WiX AllowSameVersionUpgrades) causes ICE61.
33+
34+
The chance of a hash-collision is much smaller than the chance of forgetting to update ProductId manually.
35+
-->
36+
<ProductId>EA1D5623-E6A7-4E4A-9259-E397$(GitVersion_MajorMinorPatch.GetHashCode().ToString(X8))</ProductId>
2937
</PropertyGroup>
3038
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
3139
<OutputPath>bin\$(Configuration)\</OutputPath>
3240
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
33-
<DefineConstants>Debug;PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers</DefineConstants>
41+
<DefineConstants>Debug;PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers;ProductId=$(ProductId)</DefineConstants>
3442
<Cultures>en-US</Cultures>
3543
</PropertyGroup>
3644
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
3745
<OutputPath>bin\$(Configuration)\</OutputPath>
3846
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
39-
<DefineConstants>PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers</DefineConstants>
47+
<DefineConstants>PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers;ProductId=$(ProductId)</DefineConstants>
4048
<Cultures>en-US</Cultures>
4149
</PropertyGroup>
4250
<ItemGroup>

Installer/Product.wxs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
-->
1919
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
2020
<Product
21-
Id="*"
21+
Id="$(var.ProductId)"
2222
Name="usbipd-win"
2323
Language="1033"
2424
Version="$(var.GitVersion_MajorMinorPatch)"
@@ -33,9 +33,15 @@
3333
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
3434
<?endif?>
3535

36+
<!--
37+
We guarantee that two different x.y.z versions will have a different ProductId, so
38+
everything is always a MajorUpgrade. MinorUpdates and Patches have many requirements
39+
for Feature and Component changes, which we will no doubt forget about in the future.
40+
This being a small product, a MajorUpgrade is a small price to pay to prevent any mishaps.
41+
Since we strictly follow component rules, we use afterInstallExecute to speed things up a bit.
42+
-->
3643
<MajorUpgrade
3744
Schedule="afterInstallExecute"
38-
AllowSameVersionUpgrades="yes"
3945
DowngradeErrorMessage="A newer version of [ProductName] is already installed."
4046
/>
4147

UsbIpServer/UsbIpServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<Copyright>Copyright (C) $([System.DateTime]::UtcNow.ToString("yyyy")) $(Company)</Copyright>
4242

4343
<PublishProfile>Properties\PublishProfiles\InputForInstaller.pubxml</PublishProfile>
44-
</PropertyGroup>
44+
</PropertyGroup>
4545

4646
<ItemGroup>
4747
<Content Include="..\COPYING.md" Link="COPYING.md" CopyToOutputDirectory="PreserveNewest" />

usbipd-win.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4DF1A44E-CAFC-4543-AB76-76239FBEDF03}"
99
ProjectSection(SolutionItems) = preProject
1010
.editorconfig = .editorconfig
11+
.gitattributes = .gitattributes
12+
.gitignore = .gitignore
1113
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
14+
COPYING.md = COPYING.md
1215
GitVersion.yml = GitVersion.yml
16+
README.md = README.md
17+
SECURITY.md = SECURITY.md
1318
EndProjectSection
1419
EndProject
1520
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "Installer", "Installer\Installer.wixproj", "{080EF94C-A8EC-4975-A697-BBF8C1A56055}"

0 commit comments

Comments
 (0)