Skip to content

Commit

Permalink
Load bundle variables from uninstall key
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbar committed Feb 26, 2025
1 parent 60e63e5 commit c06c432
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 18 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ on:
version:
description: 'Build & package version'
required: true
default: 0.2.4
default: 0.2.5
type: string
jobs:
Build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- uses: microsoft/setup-msbuild@v2

- name: Set version
run: Add-Content -Path $env:GITHUB_ENV -Value "FULL_VERSION=${{ github.event.inputs.version }}.${{ github.run_number }}"

- name: Build
run: dotnet build MsiZapEx.sln -p:Configuration=Release -p:Version=${{ env.FULL_VERSION }}
run: dotnet build dirs.proj -restore -p:Configuration=Release -p:FullVersion=${{ github.event.inputs.version }}.${{ github.run_number }}

- name: Publish artifacts
uses: actions/upload-artifact@v3.0.0
uses: actions/upload-artifact@v4.6.1
with:
name: MsiZapEx
path: |
Expand All @@ -41,19 +38,18 @@ jobs:
- name: Publish nuget packages to github and nuget.org
if: ${{ github.event.inputs.publish_nuget == 'true' }}
run: |
dotnet pack MsiZapEx.sln -p:Configuration=Release -p:Version=${{ env.FULL_VERSION }}
dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
dotnet nuget push build\MsiZapEx\Release\bin\MsiZapEx.${{ env.FULL_VERSION }}.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source github
dotnet nuget push build\MsiZapEx\Release\bin\MsiZapEx.${{ env.FULL_VERSION }}.nupkg --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
dotnet nuget push build\MsiZapEx\Release\bin\MsiZapEx.*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source github
dotnet nuget push build\MsiZapEx\Release\bin\MsiZapEx.*.nupkg --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
- name: Publish release
uses: softprops/action-gh-release@v2.0.8
uses: softprops/action-gh-release@v2.2.1
if: ${{ github.event.inputs.publish_release == 'true' }}
with:
prerelease: false
generate_release_notes: true
tag_name: ${{ env.FULL_VERSION }}
tag_name: ${{ env.FullVersion }}
files: |
build\MsiZapEx\Release\bin\MsiZapEx.${{ env.FULL_VERSION }}.nupkg
build\MsiZapEx\Release\bin\MsiZapEx.${{ env.FullVersion }}.nupkg
build/net40/MsiZapEx/Release/bin/MsiZapEx.exe
build/net40/MsiZapEx/Release/bin/CommandLine.dll
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
<IntDir>$(IntermediateOutputPath)</IntDir>
<OutputDirectory>$(OutputPath)</OutputDirectory>
<IntermediateDirectory>$(IntermediateOutputPath)</IntermediateDirectory>

<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<WixToolsetVersion Condition=" '$(WixToolsetVersion)' == '' ">5.0.2</WixToolsetVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="WixToolset.UI.wixext" Version="$(WixToolsetVersion)"/>
<PackageVersion Include="WixToolset.Bal.wixext" Version="$(WixToolsetVersion)"/>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />

<PackageVersion Include="TidyBuild" Version="1.5.2"/>
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions MsiZapEx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.github\workflows\build.yml = .github\workflows\build.yml
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
dirs.proj = dirs.proj
global.json = global.json
Install.txt = Install.txt
LICENSE = LICENSE
README.md = README.md
Expand All @@ -16,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MsiZapEx", "MsiZapEx\MsiZap
EndProject
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "TestPackage", "TestPackage\TestPackage.wixproj", "{491B6EDC-B0B1-4330-824C-ECB21AD5699F}"
EndProject
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "TestBundle", "TestBundle\TestBundle.wixproj", "{8E747B3F-ABFF-4844-86E5-65E0B96104DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,6 +65,22 @@ Global
{491B6EDC-B0B1-4330-824C-ECB21AD5699F}.Release|x64.Build.0 = Release|x64
{491B6EDC-B0B1-4330-824C-ECB21AD5699F}.Release|x86.ActiveCfg = Release|x86
{491B6EDC-B0B1-4330-824C-ECB21AD5699F}.Release|x86.Build.0 = Release|x86
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|Any CPU.ActiveCfg = Debug|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|Any CPU.Build.0 = Debug|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|ARM64.ActiveCfg = Debug|ARM64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|ARM64.Build.0 = Debug|ARM64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|x64.ActiveCfg = Debug|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|x64.Build.0 = Debug|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|x86.ActiveCfg = Debug|x86
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Debug|x86.Build.0 = Debug|x86
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|Any CPU.ActiveCfg = Release|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|Any CPU.Build.0 = Release|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|ARM64.ActiveCfg = Release|ARM64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|ARM64.Build.0 = Release|ARM64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|x64.ActiveCfg = Release|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|x64.Build.0 = Release|x64
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|x86.ActiveCfg = Release|x86
{8E747B3F-ABFF-4844-86E5-65E0B96104DA}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
25 changes: 25 additions & 0 deletions MsiZapEx/BundleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum StatusFlags
public List<string> Dependencies { get; private set; } = new List<string>();
public List<string> Dependents { get; private set; } = new List<string>();
public StatusFlags Status { get; private set; } = StatusFlags.None;
public Dictionary<string, object> Variables { get; private set; } = new Dictionary<string, object>();

public static List<BundleInfo> FindByUpgradeCode(Guid bundleUpgradeCode)
{
Expand Down Expand Up @@ -204,6 +205,15 @@ internal void PrintState()
{
Console.WriteLine($"\tDependent: '{d}'");
}

if (Variables.Count == 0)
{
Console.WriteLine($"\tNo persisted variables detected");
}
foreach (var v in Variables)
{
Console.WriteLine($"\tVariable: '{v.Key}'='{v.Value?.ToString()}'");
}
}

public BundleInfo(Guid bundleProductCode, RegistryView? view = null)
Expand Down Expand Up @@ -330,6 +340,21 @@ private void ReadARP(Guid bundleProductCode, RegistryView? view)
ReadDependencies(bpk);
}
}

using (var hkVariables = hkUninstall.OpenSubKey("variables"))
{
if (hkVariables != null)
{
var varNames = hkVariables.GetValueNames();
foreach (var varName in varNames)
{
if (!string.IsNullOrEmpty(varName))
{
Variables[varName] = hkVariables.GetValue(varName);
}
}
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion MsiZapEx/MsiZapEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="CommandLineParser"/>
<PackageReference Include="TidyBuild"/>
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions TestBundle/Bundle.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
<Bundle Name="TestBundle" Manufacturer="Panel::Software" Version="$(FullVersion)" UpgradeCode="d01a7a13-e3f1-457f-ba5a-2a8819942bfd">
<BootstrapperApplication>
<bal:WixStandardBootstrapperApplication LicenseUrl="https://www.example.com/license" Theme="hyperlinkLicense" />
</BootstrapperApplication>

<Variable Name="InstallFolder" Value="[ProgramFiles6432Folder]\!(bind.packageName.TestPackage.msi)" Type="formatted" Persisted="yes"/>

<Chain>
<MsiPackage SourceFile="$(TestPackage.TargetPath)">
<MsiProperty Name="INSTALLFOLDER" Value="[InstallFolder]"/>
</MsiPackage>
</Chain>

</Bundle>
</Wix>
15 changes: 15 additions & 0 deletions TestBundle/TestBundle.wixproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>Bundle</OutputType>
<DefineConstants>$(DefineConstants);FullVersion=$(FullVersion)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TestPackage\TestPackage.wixproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="WixToolset.Bal.wixext"/>
<PackageReference Include="TidyBuild"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion TestPackage/Folders.wxs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<StandardDirectory Id="ProgramFiles6432Folder">
<Directory Id="INSTALLFOLDER" Name="!(bind.Property.Manufacturer) !(bind.Property.ProductName)" />
<Directory Id="INSTALLFOLDER" Name="!(bind.Property.ProductName)" />
</StandardDirectory>
</Fragment>
</Wix>
2 changes: 1 addition & 1 deletion TestPackage/Package.wxs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="TestPackage" Manufacturer="TODO Manufacturer" Version="1.0.0.0" UpgradeCode="270775df-83c8-42fa-b78f-4713cb37d84d">
<Package Name="TestPackage" Manufacturer="Panel::Software" Version="$(FullVersion)" UpgradeCode="270775df-83c8-42fa-b78f-4713cb37d84d">
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />

<UIRef Id="WixUI_FeatureTree_$(sys.BUILDARCHSHORT)"/>
Expand Down
8 changes: 6 additions & 2 deletions TestPackage/TestPackage.wixproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project Sdk="WixToolset.Sdk/5.0.0">
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<DefineConstants>$(DefineConstants);FullVersion=$(FullVersion)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WixToolset.UI.wixext" Version="5.0.0"/>
<PackageReference Include="WixToolset.UI.wixext"/>
<PackageReference Include="TidyBuild"/>
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions dirs.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.Build.Traversal">
<PropertyGroup>
<TraversalGlobalProperties>SolutionDir=$(MSBuildThisFileDirectory);Configuration=$(Configuration);BuildProjectReferences=false</TraversalGlobalProperties>
<CustomBeforeTraversalProps>$(MSBuildThisFileDirectory)Directory.Build.props</CustomBeforeTraversalProps>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="MsiZapEx\MsiZapEx.csproj" Properties="Platform=Any CPU;GeneratePackageOnBuild=true" Targets="Build" BuildInParallel="false"/>
</ItemGroup>
<ItemGroup Condition="'$(BuildSample)' != '' And $(BuildSample)">
<ProjectReference Include="TestPackage\TestPackage.wixproj" Properties="Platform=x64" Targets="Build" BuildInParallel="false"/>
<ProjectReference Include="TestBundle\TestBundle.wixproj" Properties="Platform=x64" Targets="Build" BuildInParallel="false"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="TidyBuild" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"msbuild-sdks": {
"WixToolset.Sdk": "5.0.2",
"Microsoft.Build.Traversal": "4.1.0"
}
}

0 comments on commit c06c432

Please sign in to comment.