0

我有一个使用 Serilog 的非常简单的 C# Windows 窗体应用程序。我想使用 WIX 为我的应用程序创建一个 MSI 安装程序,并且我想在其中包含一些 Serilog DLL。

到目前为止,我已成功配置 Product.WXS 以复制所有三个 Serilog 文件;但是,在此过程中会覆盖若干文件元数据,包括文件版本和产品版本。

这是有道理的(我认为?),因为这些文件作为我的产品的组件包含在内,所以它们就像我的 EXE 一样得到版本控制。

结果,当我运行我的应用程序时,我收到一个 File or Assembly Not Found 错误(因为我的应用程序正在寻找一个与 MSI 安装后版本不同的 Serilog DLL)。

我确定我在这里遗漏了一些非常简单的东西。

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="MyProject" Language="1033" Version="1.0.0" Manufacturer="Acme, Inc" UpgradeCode="36202e76-0c43-492e-98d8-f9ff7e402f55">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Platform="x64" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFiles64Folder">
        <Directory Id="INSTALLFOLDER" Name="MyProjectInstallDir" >
          <Component Id="ProductComponent">
            <File Id="MYPROJECT_EXE" Name="MyProject.exe" Source="$(var.MyProject.TargetPath)"/>
          </Component>
          <Component Id="Serilog_dll" >
            <File Id="Serilog_dll" Name="Serilog.dll" KeyPath="yes" Source="$(var.MyProject.TargetPath)" />
          </Component>
          <Component Id="Serilog_Sinks_dll" >
            <File Id="Serilog_Sinks_File_dll" Name="Serilog.Sinks.File.dll" Source="$(var.MyProject.TargetPath)" />
          </Component>
          <Component Id="Serilog_Sinks_xml">
            <File Id="Serilog_Sinks_File_xml" Name="Serilog.Sinks.File.xml" Source="$(var.MyProject.TargetPath)"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="ProductFeature" Level="1">
      <ComponentRef Id="ProductComponent"/>
      <ComponentRef Id="Serilog_dll"/>
      <ComponentRef Id="Serilog_Sinks_dll"/>
      <ComponentRef Id="Serilog_Sinks_xml"/>
    </Feature>
    </Product>
</Wix>

我期望的是所有三个 Serilog 文件都由 MSI 安装,并且它们具有正确的版本号和元数据。

基本上,我想做的是“复制”文件而不对它们进行版本控制。

就像我说的,我毫不怀疑这是可能的,而且可能是直截了当的,我只是 WIX 的新手。

4

1 回答 1

1

好的,我想通了。我是 WIX 的新手,所以请原谅我,因为这绝对是一个新手错误。

请注意,在上面的代码中,我使用了以下组件来复制 Serilog DLL:

<Component Id="Serilog_dll" >
            <File Id="Serilog_dll" Name="Serilog.dll" KeyPath="yes" Source="$(var.MyProject.TargetPath)" />
</Component>

问题在于 Source 值 (var.MyProject.TargetPath),它不是指 /Release 目录,而是指 /Release/MyProject.exe 文件(参见参考资料)。

我用 var.MyProject.TargetDir 替换了它,如下所示:

<Component Id="Serilog_dll">
            <File Id="Serilog_dll" Source="$(var.MyProject.TargetDir)" Name="Serilog.dll" />
</Component>

构建/运行 MSI 后,Serilog dll 将包含正确的版本和文件信息。

于 2019-11-05T13:58:01.093 回答