I am having some trouble trying to perform automatic installations after a registry search to see installed versions of specific software. This custom action should then set a conditional variable to "1" and then using the condition in my .wxs file conditionally install the correct files. If I comment out the conditions it installs without issue. Checked logs and the conditions are being set to "1" but it seems to be ignored in the condition logic. Heres my code:
<Feature Id="ProductFeature" Title="MAJExportAddinInstaller" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<!-- Add Custom Action references -->
<Binary Id="RevitVersionCheckerDLL" SourceFile="C:\Users\mmckeon\Desktop\MAJExportAddinInstaller\MAJExportAddinInstaller\CustomActions\RevitVersionChecker_2.CA.dll"/>
<CustomAction Id="SetPropertiesForAction" BinaryKey="RevitVersionCheckerDLL" DllEntry="CheckRevitVersion" Execute="immediate" />
<Property Id="REVIT_PATHS" Secure="yes" />
<Property Id="WIXUI_INSTALLDIR" Value="TARGETDIR" />
<Property Id="REVIT2020INSTALLED" Secure="yes" />
<Property Id="REVIT2021INSTALLED" Secure="yes" />
<Property Id="REVIT2022INSTALLED" Secure="yes"/>
<Property Id="REVIT2023INSTALLED" Secure="yes"/>
<Property Id="REVIT2024INSTALLED" Secure="yes"/>
<!-- Conditionally run Custom Action -->
<InstallExecuteSequence>
<!-- Run the Custom Action to set the properties based on registry checks -->
<Custom Action="SetPropertiesForAction" After="CostFinalize">
(NOT Installed)
</Custom>
<!-- Check for the Revit versions after the AppSearch standard action -->
<LaunchConditions After="AppSearch">
REVIT2020INSTALLED OR REVIT2021INSTALLED OR REVIT2022INSTALLED OR REVIT2023INSTALLED OR REVIT2024INSTALLED
</LaunchConditions>
</InstallExecuteSequence>
<UIRef Id="WixUI_Minimal"/>
</Product>
<Fragment>
<UIRef Id="WixUI_ErrorProgressText" />
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramDataFolder" Name="ProgramData">
<Directory Id="AutodeskFolder" Name="Autodesk">
<Directory Id="RevitFolder" Name="Revit">
<Directory Id="INSTALLFOLDER" Name="Addins">
<!--2020-->
<Directory Id="Revit2020" Name="2020">
<Component Id="Revit2020AddinFiles" Guid="01937BED-93D9-439C-8B58-73EA46A2E862">
<Condition>REVIT2020INSTALLED</Condition>
<File Id="MAJExporterAddinLocation1" Source="InstallerResources\2020\MAJExporter.addin" KeyPath="yes" />
</Component>
<Directory Id="Resources2020" Name="Resources">
<Component Id="Resources2020Files" Guid="91805D1D-C462-4C51-9486-E1C1C7A68D97">
<Condition>REVIT2020INSTALLED</Condition>
<File Id="MAJExporterAddinLocation2" Source="InstallerResources\2020\Resources\export_icon.png" KeyPath="yes" />
</Component>
</Directory>
<Directory Id="MAJExportAddin2020">
<Component Id="MAJExportAddin2020Files" Guid="D82D4E72-A1B9-4EA9-A8C6-6A9FFF2C8AD2">
<Condition>REVIT2020INSTALLED</Condition>
<File Id="MAJExporterAddinLocation3" Source="InstallerResources\2020\MAJExporter.dll" KeyPath="yes" />
</Component>
</Directory>
</Directory>
and my custom action code:
public class VersionCheckActions
{
[CustomAction]
public static ActionResult CheckRevitVersion(Session session)
{
session.Log("Begin CheckRevitVersion");
List<string> revitPaths = new List<string>();
try
{
// Check for the existence of each Revit version
CheckAndSetProperty(session, "2020", "REVIT2020INSTALLED", revitPaths);
CheckAndSetProperty(session, "2021", "REVIT2021INSTALLED", revitPaths);
CheckAndSetProperty(session, "2022", "REVIT2022INSTALLED", revitPaths);
CheckAndSetProperty(session, "2023", "REVIT2023INSTALLED", revitPaths);
CheckAndSetProperty(session, "2024", "REVIT2024INSTALLED", revitPaths);
// Concatenate the paths
session["REVIT_PATHS"] = string.Join("; ", revitPaths);
session.Log("Completed CheckRevitVersion");
return ActionResult.Success;
}
catch (Exception ex)
{
session.Log($"Exception in CheckRevitVersion: {ex.Message}");
return ActionResult.Failure;
}
}
[CustomAction]
private static void CheckAndSetProperty(Session session, string version, string installFlagProperty, List<string> revitPaths)
{
var regKeyPath = $@"SOFTWARE\Autodesk\Revit\{version}";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regKeyPath))
{
session.Log($"Checking registry path: {regKeyPath}");
if (key != null)
{
session[installFlagProperty] = "1"; // set the property if the registry key exists
session.Log($"Registry key found. Setting {installFlagProperty}.");
string installPath = $@"C:\ProgramData\Autodesk\Revit\Addins\{version}";
revitPaths.Add(installPath);
session.Log($"Added installation path: {installPath}");
}
else
{
session.Log($"Registry key not found for {version}.");
}
}
}
Please help I have been stuck on this for two days! Happy to add more code if required, hopefully this makes sense for you!
Ahhh....it needed to be this. 2 days i spent on this.....
Needed to use
<InstallUISequence>