WiX Toolset中EventSource的EventMessageFile路径被错误添加#%前缀
WiX 4.0 EventSource EventMessageFile注册表路径异常问题
我在WiX 4.0项目中使用Util工具创建Windows EventLog事件源,遇到的问题是:EventMessageFile对应的注册表条目被错误添加了##%前缀,导致该事件源生成的事件在事件日志中显示错误。
我的WiX代码
<Include xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> <PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR64"/> <PropertyRef Id="NETFRAMEWORK40CLIENTINSTALLROOTDIR64"/> <PropertyRef Id="NETFRAMEWORK40CLIENT"/> <PropertyRef Id="NETFRAMEWORK40FULL"/> ... <ComponentGroup Id="EventLog" Directory="INSTALLFOLDER"> <!-- 64 bit --> <Component Id="CreateEventSource64BitFullNet4" DiskId="1" Guid="{9978592B-3E96-4AAA-B7A6-34B0421FDD02}" Condition="NETFRAMEWORK40FULLINSTALLROOTDIR64 AND VersionNT64"> <CreateFolder/> <util:EventSource Log="Application" Name="ScholarshipSapQueue" EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR64]EventLogMessages.dll" /> </Component> <Component Id="CreateEventSource64BitClientNet4" DiskId="1" Guid="{B42622A1-B7C0-48CB-B306-65F3558C6678}" Condition="NETFRAMEWORK40CLIENTINSTALLROOTDIR64 AND NOT NETFRAMEWORK40FULL AND VersionNT64"> <CreateFolder/> <util:EventSource Log="Application" Name="ScholarshipSapQueue" EventMessageFile="[NETFRAMEWORK40CLIENTINSTALLROOTDIR64]EventLogMessages.dll" /> </Component> </ComponentGroup> </Include>
MSI安装日志中的属性值(正常)
MSI (c) (B4:68) [10:05:27:331]: PROPERTY CHANGE: Adding NETFRAMEWORK40FULLINSTALLROOTDIR64 property. Its value is 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\'.
注册表写入日志(异常)
MSI (s) (3C:28) [10:05:33:008]: Executing op: ActionStart(Name=WriteRegistryValues,Description=Writing system registry values,Template=Key: [1], Name: [2], Value: [3]) Action 10:05:33: WriteRegistryValues. Writing system registry values MSI (s) (3C:28) [10:05:33:014]: Executing op: ProgressTotal(Total=1,Type=1,ByteEquivalent=13200) MSI (s) (3C:28) [10:05:33:014]: Executing op: RegOpenKey(Root=-2147483646,Key=SYSTEM\CurrentControlSet\Services\EventLog\Application\ScholarshipSapQueue,,BinaryType=0,,) MSI (s) (3C:28) [10:05:33:014]: Executing op: RegAddValue(Name=EventMessageFile,Value=##%C:\Windows\Microsoft.NET\Framework64\v4.0.30319\EventLogMessages.dll,) WriteRegistryValues: Key: \SYSTEM\CurrentControlSet\Services\EventLog\Application\ScholarshipSapQueue, Name: EventMessageFile, Value: ##%C:\Windows\Microsoft.NET\Framework64\v4.0.30319\EventLogMessages.dll
注册表路径错误截图

解决方案
这个问题是WiX 4.0中util:EventSource处理.NET框架属性时的转义问题,有两种可行的解决方式:
方式1:使用[~PROPERTY]格式引用属性
修改EventMessageFile的属性引用方式,在属性名前添加~,让WiX直接输出属性原始值,避免不必要的转义:
<!-- 修正后的FullNet4组件 --> <util:EventSource Log="Application" Name="ScholarshipSapQueue" EventMessageFile="[~NETFRAMEWORK40FULLINSTALLROOTDIR64]EventLogMessages.dll" /> <!-- 修正后的ClientNet4组件 --> <util:EventSource Log="Application" Name="ScholarshipSapQueue" EventMessageFile="[~NETFRAMEWORK40CLIENTINSTALLROOTDIR64]EventLogMessages.dll" />
方式2:手动创建注册表项替代util:EventSource
直接通过RegistryKey和RegistryValue手动写入注册表,完全控制路径内容:
<Component Id="CreateEventSource64BitFullNet4" DiskId="1" Guid="{9978592B-3E96-4AAA-B7A6-34B0421FDD02}" Condition="NETFRAMEWORK40FULLINSTALLROOTDIR64 AND VersionNT64"> <CreateFolder/> <RegistryKey Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\EventLog\Application\ScholarshipSapQueue"> <RegistryValue Name="EventMessageFile" Value="[NETFRAMEWORK40FULLINSTALLROOTDIR64]EventLogMessages.dll" Type="string"/> <RegistryValue Name="TypesSupported" Value="7" Type="integer"/> </RegistryKey> </Component>
内容的提问来源于stack exchange,提问作者Daniel Schmid
相关产品推荐
相关产品推荐

