From c06c4326b4f659071c6156c2d3cb0ba4af4c2b50 Mon Sep 17 00:00:00 2001 From: Nir Bar Date: Wed, 26 Feb 2025 15:44:29 +0200 Subject: [PATCH] Load bundle variables from uninstall key --- .github/workflows/build.yml | 22 +++++++++------------- Directory.Build.props | 4 ++++ Directory.Packages.props | 14 ++++++++++++++ MsiZapEx.sln | 21 +++++++++++++++++++++ MsiZapEx/BundleInfo.cs | 25 +++++++++++++++++++++++++ MsiZapEx/MsiZapEx.csproj | 3 ++- TestBundle/Bundle.wxs | 16 ++++++++++++++++ TestBundle/TestBundle.wixproj | 15 +++++++++++++++ TestPackage/Folders.wxs | 2 +- TestPackage/Package.wxs | 2 +- TestPackage/TestPackage.wixproj | 8 ++++++-- dirs.proj | 17 +++++++++++++++++ global.json | 6 ++++++ 13 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 Directory.Packages.props create mode 100644 TestBundle/Bundle.wxs create mode 100644 TestBundle/TestBundle.wixproj create mode 100644 dirs.proj create mode 100644 global.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b4660cc..1f146cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: | @@ -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 diff --git a/Directory.Build.props b/Directory.Build.props index 25725c7..195bd2c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,5 +15,9 @@ $(IntermediateOutputPath) $(OutputPath) $(IntermediateOutputPath) + + false + false + false diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..13097ec --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,14 @@ + + + true + 5.0.2 + + + + + + + + + + diff --git a/MsiZapEx.sln b/MsiZapEx.sln index 308eb91..fc15165 100644 --- a/MsiZapEx.sln +++ b/MsiZapEx.sln @@ -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 @@ -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 @@ -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 diff --git a/MsiZapEx/BundleInfo.cs b/MsiZapEx/BundleInfo.cs index 05f1434..419bb90 100644 --- a/MsiZapEx/BundleInfo.cs +++ b/MsiZapEx/BundleInfo.cs @@ -37,6 +37,7 @@ public enum StatusFlags public List Dependencies { get; private set; } = new List(); public List Dependents { get; private set; } = new List(); public StatusFlags Status { get; private set; } = StatusFlags.None; + public Dictionary Variables { get; private set; } = new Dictionary(); public static List FindByUpgradeCode(Guid bundleUpgradeCode) { @@ -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) @@ -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); + } + } + } + } } } } diff --git a/MsiZapEx/MsiZapEx.csproj b/MsiZapEx/MsiZapEx.csproj index a0bbab9..e26dc7f 100644 --- a/MsiZapEx/MsiZapEx.csproj +++ b/MsiZapEx/MsiZapEx.csproj @@ -29,7 +29,8 @@ - + + diff --git a/TestBundle/Bundle.wxs b/TestBundle/Bundle.wxs new file mode 100644 index 0000000..fb4c6b4 --- /dev/null +++ b/TestBundle/Bundle.wxs @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/TestBundle/TestBundle.wixproj b/TestBundle/TestBundle.wixproj new file mode 100644 index 0000000..270b961 --- /dev/null +++ b/TestBundle/TestBundle.wixproj @@ -0,0 +1,15 @@ + + + Bundle + $(DefineConstants);FullVersion=$(FullVersion) + + + + + + + + + + + diff --git a/TestPackage/Folders.wxs b/TestPackage/Folders.wxs index eaa4246..b6a0762 100644 --- a/TestPackage/Folders.wxs +++ b/TestPackage/Folders.wxs @@ -1,7 +1,7 @@ - + diff --git a/TestPackage/Package.wxs b/TestPackage/Package.wxs index f2cbb62..2dbf4a4 100644 --- a/TestPackage/Package.wxs +++ b/TestPackage/Package.wxs @@ -1,5 +1,5 @@  - + diff --git a/TestPackage/TestPackage.wixproj b/TestPackage/TestPackage.wixproj index da454c8..ff1b607 100644 --- a/TestPackage/TestPackage.wixproj +++ b/TestPackage/TestPackage.wixproj @@ -1,6 +1,10 @@ - + + + $(DefineConstants);FullVersion=$(FullVersion) + - + + diff --git a/dirs.proj b/dirs.proj new file mode 100644 index 0000000..4f2d83b --- /dev/null +++ b/dirs.proj @@ -0,0 +1,17 @@ + + + SolutionDir=$(MSBuildThisFileDirectory);Configuration=$(Configuration);BuildProjectReferences=false + $(MSBuildThisFileDirectory)Directory.Build.props + + + + + + + + + + + + + diff --git a/global.json b/global.json new file mode 100644 index 0000000..8330e47 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "msbuild-sdks": { + "WixToolset.Sdk": "5.0.2", + "Microsoft.Build.Traversal": "4.1.0" + } +}