Questions100
Questions100

Reputation: 71

Wix Custom actions run dll c#

I'm using a custom action to run a function from dll, but when I run the msi I built, I get the error:

"There is a problem with this windows installer package. A DLL required for this install to complete could not be run. Contact you support..."

This is what I did:

       <Fragment>
<UI>
  <Dialog Id="UserRegistrationDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes">

    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next">
      <Publish Event="DoAction" Value="MyCustomAction">1</Publish>
      <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">CostingComplete = 1</Publish>
      <Publish Event="NewDialog" Value="SetupTypeDlg">ProductID</Publish>
    </Control>
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
    <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />
    <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes">
      <Text>Please enter your customer information</Text>
    </Control>
    <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
    <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes">
      <Text>{\WixUI_Font_Title}Customer Information</Text>
    </Control>
    <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />

  <Control Id="PlatformCombobox" Type="ComboBox" X="45" Y="127" Width="220" Height="18" ComboList="yes" Sorted="yes" Property="Platform">
    <ComboBox Property="Platform">
      <ListItem Value="1" Text="1"/>
      <ListItem Value="2" Text="2 "/>
      <ListItem Value="3" Text="3 "/>
      <ListItem Value="4" Text="4 "/>
    </ComboBox>
  </Control>
  </Dialog>
</UI>
    <Property Id="Platform" Value="2" />

    <CustomAction Id='MyCustomAction' BinaryKey='CreateFile' DllEntry='CreateFile'/>
    <Binary Id='CreateFile' SourceFile='SetupDll.dll'/>


  </Fragment>

As you can see I'm trying to run SetupDll.dll which contains 1 class with 1 function:

using System.IO;
using Microsoft.Deployment.WindowsInstaller;

namespace SetupDll
{
    public class Creator
    {
        [CustomAction]
        public static ActionResult CreateFile(Session session)
        {
            File.WriteAllText(@"C:\a.txt", "123");
            return ActionResult.Success;
        }
    }
}

But I dont understand the problem. I placed the resulting SetupDll.dll in every folder of the wix project..

Thank you!

Upvotes: 1

Views: 1970

Answers (2)

Stein &#197;smul
Stein &#197;smul

Reputation: 42136

MakeSfxCA.exe: The FileName.CA.dll dll is essentially an bundle of your .NET managed code dll and dependencies and it emulates a real dll so that MSI can handle it as custom action. It is made using a file called MakeSfxCA.exe - There are some details here (also see answer number 2 in that "thread").

If you do things correctly in Visual Studio WiX / Votive does this compilation using MakeSfxCA.exe auto-magically for you. See screen shot in link above.

There are some samples of how to use managed code here:

Inline, the essence. Notice the ".CA.dll" at the end of the line for the Binary element:

<..>

<!-- Point to custom action binary -->
<Binary Id="CustomActions" SourceFile="$(var.CustomAction1.TargetDir)\$(var.CustomAction1.TargetName).CA.dll" />

<!-- Specify custom action name in above binary -->
<CustomAction Id="CA1" BinaryKey="CustomActions" DllEntry="CustomAction1"/>

<!-- Insert custom action in GUI sequence -->
<InstallUISequence>
  <Custom Action="CA1" After="CostFinalize" />
</InstallUISequence>

<!-- Insert custom action in install sequence -->
<InstallExecuteSequence>
  <Custom Action="CA1" After="CostFinalize" />
</InstallExecuteSequence>

<..>

Upvotes: 1

Christopher Painter
Christopher Painter

Reputation: 55581

The binary element should point to the SetupDll.CA.dll not the SetupDll.dll.

Upvotes: 0

Related Questions