First create a c# class library. I targeted .NET 4.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Deployment.WindowsInstaller;
public class SampleCheckPID
    public static ActionResult CheckPID(Session session)
        //        string Pid = session["PIDKEY"];
        //        session["PIDACCEPTED"] = Pid.StartsWith("1") ? "1" : "0";
        System.IO.File.AppendAllText(@"c:\log.txt", string.Format("{0}\r\n", @"from wfwica\"));

        return ActionResult.Success;

To compile into a .NET DLL, you need to reference:

C:\Program Files\Windows Installer XML v3.5\SDK\Microsoft.Deployment.WindowsInstaller.dll

The custom action takes one parameter, “Session” object from which you can read and write properties. Look at the comment part of the code. Session is an associated array / map. In the sample above, I just wrote a single line to a disk file so that I could see that the custom action worked. Build that DLL.

Next, you need to use the MakeSfxCA command-line tool to convert that DLL that MSI understands. In my test, I called the C# DLL “wfwica.dll”, then issued the following command:

MakeSfxCA.exe "C:\Projects\winformWinstall\wfwica\bin\Debug\wfwicaPackage.dll" "C:\program files\Windows Installer XML v3.5\SDK\x86\sfxca.dll" "C:\Projects\winformWinstall\wfwica\bin\Debug\wfwica.dll" "C:\Projects\winformWinstall\wfwica\CustomAction.config" "C:\program files\Windows Installer XML v3.5\bin\Microsoft.Deployment.WindowsInstaller.dll"

Which ends up creating wfwicaPackage.dll in the same folder. MakeSfxCA.exe requires absolute paths.

Then, in your WiX source file, you reference wfwicaPackage.dll.

Oh, one more thing, the above line requires the file: CustomAction.config. I used this:

<?xml version="1.0" encoding="utf-8" ?>

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>

Then in your .wxs file use a custom action as usual:

    <CustomAction Id='CheckingPID' BinaryKey='CheckPID' DllEntry='CheckPID' />

      <Custom Action='CheckingPID' After='CostFinalize' />

    <Binary Id='CheckPID' SourceFile='C:\Projects\winformWinstall\wfwica\bin\Debug\wfwicaPackage.dll' />

Enabled full logging in MSI to see what was going on:

msiexec /i yourmsi.msi /l*v msilog.txt
Community content is available under CC-BY-SA unless otherwise noted.