在注册表搜索以查看特定软件的已安装版本后,我在尝试执行自动安装时遇到一些问题。然后,此自定义操作应将条件变量设置为“1”,然后使用我的 .wxs 文件中的条件有条件地安装正确的文件。如果我注释掉它安装的条件就没有问题。检查日志并且条件被设置为“1”,但它似乎在条件逻辑中被忽略。 这是我的代码:
<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>
和我的自定义操作代码:
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}.");
}
}
}
请帮助我已经被这个问题困扰了两天了!如果需要,很高兴添加更多代码,希望这对您有意义!
啊……必须是这个。我花了2天时间在这上面......
<InstallUISequence>
<!-- 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">
<![CDATA[REVIT2020INSTALLED OR REVIT2021INSTALLED OR REVIT2022INSTALLED OR REVIT2023INSTALLED OR REVIT2024INSTALLED]]>
</LaunchConditions>
</InstallUISequence>
需要使用
<InstallUISequence>