apamburn
apamburn

Reputation: 311

How to copy third party DLLs with WIX

I have a pretty simple C# Windows Forms application that uses Serilog. I want to use WIX to create an MSI installer for my application, and I want to include a few Serilog DLLs with it.

So far I have successfully configured Product.WXS to copy over all three Serilog files; however, several pieces of file metadata are getting overwritten in the process, including File version and Product Version.

This makes sense (I think?) because the files are being included as components of my product, so they get versioned just like my EXE.

As a consequence, when I run my application I get a File or Assembly Not Found error (since my application is looking for a Serilog DLL with a different version than it's finding after install by MSI).

I'm sure I'm missing something very simple here.

<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>

What I expect is that all three of the Serilog files get installed by the MSI, and that they have the correct version number and metadata.

Basically, what I want to do is to "copy" the files without versioning them.

Like I said, I have no doubt that this is possible, and probably straight forward, I am just new to WIX.

Upvotes: 0

Views: 893

Answers (1)

apamburn
apamburn

Reputation: 311

OK, I figured this out. I'm a newb to WIX so forgive me, as this was definitely a rookie mistake.

Notice that in the code snipped above I used the following Component to copy the Serilog DLL:

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

The problem with that is the Source value (var.MyProject.TargetPath), which doesn't refer to the /Release directory, but instead the /Release/MyProject.exe file (see reference).

I replaced that with var.MyProject.TargetDir as follows:

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

After building / running MSI the Serilog dll is being included with the correct version and file information.

Upvotes: 2

Related Questions