我想要使用WiX创建的MSI安装程序来运行自定义操作,该操作创建并加密安装程序属性(日期),然后将其写入注册表项值(进入HKLM)。我遇到的问题是在写入注册表时没有更新属性(由于在自定义操作中创建了属性而写入空字符串)。我认为它与自定义操作正在执行的顺序有关,但我已经尝试将序列链中的自定义操作移动到较早的阶段(序列为99),但这并没有奏效。我想注意日志文件显示属性正在更新
wix .wxs的当前设置
<InstallExecuteSequence>
<Custom Action="CustomActionTest" Before="WriteRegistryValues"/>
</InstallExecuteSequence>
<Fragment>
<Binary Id="CustomActionBinary" SourceFile="..\CustomActionTest.CA.dll"/>
<CustomAction Id="CustomActionTest" BinaryKey="CustomActionBinary" DllEntry="CustomAction1" Execute="firstSequence" Return="check"/>
</Fragment>
<Component Id="CMP_WriteToLicenseRegistry" Guid="{}" Permanent="yes">
<RegistryKey Root="HKLM" Key="SOFTWARE\Test">
<RegistryValue Action="write" Name="TestDate" Type="string" Value="[TestDateRegistryValue]"/>
</RegistryKey>
</Component>
CustomActionTest.CA.dll中的自定义操作
[CustomAction]
public static ActionResult CustomAction1(Session session) {
session.Log("VALUE BEFORE " + session["TestDateRegistryValue"]);
session.Log("Begin CustomAction1");
session["TestDateRegistryValue"] = DateTime.Now;
session.Log("VALUE AFTER " + session["TestDateRegistryValue"]);
session.Log("End CustomAction1");
return ActionResult.Success;
}
答案 0 :(得分:0)
自定义操作在第一个序列中运行,并作为立即(默认类型)操作。这意味着它将在msi安装程序的“客户端”阶段运行。
WriteRegistryValues操作在服务器阶段运行,只能访问此阶段中可用的属性。这包括msi数据库本身的属性的默认值以及标记为secure的任何公共属性。
要使您的属性值在服务器阶段可用,您必须将其标记为Secure='yes'
。要将财产标记为安全,它也必须是公共财产,这意味着它需要具有全部资本名称。
因此,如果您将属性更新为
,则应该能够正确设置注册表值<Property Name="TESTDATEREGISTRYVALUE" Secure="yes">
并更新自定义操作中的名称和<RegistryValue>
。