【问题标题】:WiX to install EventSourceWiX 安装 EventSource
【发布时间】:2014-04-02 20:21:27
【问题描述】:

我基于此example 创建了我的事件源。我的事件源如下所示:

[EventSource(Name = "Samples-EventSourceDemos-EventLog")]
public sealed class MinimalEventSource : EventSource
{
    public static MinimalEventSource Log = new MinimalEventSource();

    [Event(1, Message = "{0} -> {1}", Channel = EventChannel.Admin)]
    public void Load(long baseAddress, string imageName)
    {
        WriteEvent(1, baseAddress, imageName);
    }
}

示例使用代码来模拟安装/卸载过程。从其他一些 SO 问题中,我看到另一个 example 使用事件消息文件安装事件源。

但是它缺少一些如何安装/注册由清单定义的事件源的好例子。我正在调查使用 CustomAction 执行以下操作:

wevtutil.exe im <EtwManifestManFile> /rf:"EtwManifestDllFile" /mf:"EtwManifestDllFile"

但想知道您是否有任何建议?

【问题讨论】:

    标签: c# wix event-log wix3.5 eventlog-source


    【解决方案1】:

    经过一番搜索后想通了。在 WixUtilExtension 中,有内置支持。引用它并添加命名空间后,就很简单了。

    这是 Product.wxs 中的更改:

    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
         xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    ...
          <Component Id="etwManifest.dll">
            <File Id="etwManifest.dll" KeyPath="yes"
                  Source="$(var.SampleClassLibrary.TargetDir)\SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll" />
          </Component>
          <Component Id="etwManifest.man">
            <File Id="etwManifest.man" KeyPath="yes"
                  Source="$(var.SampleClassLibrary.TargetDir)\SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.man">
              <util:EventManifest  MessageFile="[etwManifest.dll]"  ResourceFile="[etwManifest.dll]"></util:EventManifest>
            </File>
          </Component>
    </Wix>
    

    我必须做的唯一技巧是减少组件 ID 和文件 ID(用于与文件名匹配)的长度以避免以下错误:错误 25540。配置 XML 文件时出现故障。

    【讨论】:

    • 这会为我安装事件清单,但我的进程无法记录任何事件。使用 WiX 3.9。
    • 似乎对我有用。如果您使用的是“调试”类型的通道,则只有在视图菜单中选择了“显示分析和调试日志”选项时,才能在 eventvwr.msc 中看到它。确保您已启用 eventvwr.msc 中的日志。
    • 我需要在 util:EventManifest 元素中使用 [#fileId] 而不是 [fileId],因此: 而不是: 使其工作。否则,生成的 .etwManifest.man 文件包含引用的空字符串: messageFileName="" resourceFileName="" 我在 windows-installer-xml-wix-toolset.687559.n2.nabble.com/… 上找到了这种方法
    【解决方案2】:

    对我来说,解决方案是为 .dll 和 .man 这两个文件添加权限。 (https://stackoverflow.com/a/32727624/5500092)

    <util:PermissionEx User="Everyone" ReadPermission="yes" ReadAttributes="yes" ReadExtendedAttributes="yes" />
    

    我还必须添加完整路径才能正确注册清单文件。当我没有这样做时,清单文件仍然引用我的 Visual Studio 解决方案的 bin/release 文件夹。

    <util:EventManifest MessageFile="[INSTALLFOLDER]SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll" ResourceFile="[INSTALLFOLDER]SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll"/>
    

    代码:

    <DirectoryRef Id="INSTALLFOLDER">
        <Component Id="etwManifest.dll" Guid="PUT-GUID-HERE">
            <File Id="etwManifest.dll" KeyPath="yes"  Source="$(var.SampleClassLibrary.TargetDir)\SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll" >
                <util:PermissionEx User="Everyone" ReadPermission="yes" ReadAttributes="yes" ReadExtendedAttributes="yes" />
                 <util:PermissionEx User="Administrators"   ReadPermission="yes" ReadAttributes="yes" ReadExtendedAttributes="yes"/>
            </File>
        </Component>
    
        <Component Id="etwManifest.man" Guid="PUT-GUID-HERE">
            <File Id="etwManifest.man" KeyPath="yes" Source="$(var.SampleClassLibrary.TargetDir)\SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.man" >
                <util:PermissionEx User="Everyone"   ReadPermission="yes" ReadAttributes="yes" ReadExtendedAttributes="yes"/>
                <util:PermissionEx User="Administrators"   ReadPermission="yes" ReadAttributes="yes" ReadExtendedAttributes="yes"/>
                <util:EventManifest MessageFile="[INSTALLFOLDER]SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll" ResourceFile="[INSTALLFOLDER]SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll"/>
            </File>
        </Component>
    </DirectoryRef>
    

    使用 WiX 工具集 v3.10

    (如果我的英语不好,请纠正我)

    【讨论】:

      猜你喜欢
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 2011-03-28
      • 2013-02-18
      • 1970-01-01
      相关资源
      最近更新 更多