c00000fd
c00000fd

Reputation: 22317

How to include a native DLL into my managed DLL/custom action for the WiX installer?

I'm making a WiX/MSI installer that uses a custom action DLL written in C#. Inside that custom action I'm pinvoking a native/unmanaged DLL. Here's an example:

    [DllImport("log.dll",
        CharSet = CharSet.Unicode,
        SetLastError = true,
        CallingConvention = CallingConvention.StdCall)]
    static extern int CloseLog(IntPtr hLog);

The problem is that when my MSI runs and I invoke the custom action my call to CloseLog throws the DllNotFoundException exception.

I can manually add a link to log.dll into my custom action C# DLL project:

enter image description here

But the problem is that there's no way to specify which build of the log.dll to use from a C# project, i.e. x86/x64/debug/release.

So any suggestions how to do it?

Upvotes: 1

Views: 845

Answers (3)

scaler
scaler

Reputation: 574

You can add any payload to the CA.dll by defining CustomActionContents in the project file like this (left path is in the CA right path is your local path).

  <PropertyGroup>
    <CustomActionContents>x64\log.dll=x64\log.dll;</CustomActionContents>
  </PropertyGroup>

Update: This works the same in WiX v4. Forward slashes / do not work.

Upvotes: 2

c00000fd
c00000fd

Reputation: 22317

Have to answer my own question.

Evidently there's no way to do this via UI. So instead right-click your C# project in Solution Explorer, and select Unload Project, then locate the file name in the XML markup. So it turns out that instead of:

  <ItemGroup>
    <Content Include="..\..\..\x64\Debug\log.dll">
      <Link>Properties\log.dll</Link>
    </Content>
  </ItemGroup>

you can do:

  <ItemGroup>
    <Content Include="..\..\..\$(Platform)\$(Configuration)\log.dll">
      <Link>Properties\log.dll</Link>
    </Content>
  </ItemGroup>

Then right-click the project again and select Reload Project.

It won't show correctly in the properties window, but it will compile according to selected configuration.

Upvotes: 0

Christopher Painter
Christopher Painter

Reputation: 55601

Add the DLL as content copylocal=true and it'll be included in the current directory of the custom action.

MSI is not platform agnostic so you should build a 32bit CA and 64bit CA to be consumed by a 32bit MSI and a 64bit MSI if straight up x64/Release doesn't work for you.

Upvotes: 0

Related Questions