kudlatiger
kudlatiger

Reputation: 3278

How to log custom messages in Wix Installer code?

Here is my Wix code in .wxs file

      <Component Id="MyRootCA.cer" Guid="*" Permanent="yes">
      <File Id="MyRootCAFile.cer" Name="MyRootCA.cer" Source="Assets\Certificates\MyRootCA.cer" />
      <iis:Certificate Id="Certificate.MyRootCA"
                       Name="MyRootCA.cer"
                       Request="no"
                       StoreLocation="localMachine"
                       StoreName="root"
                       Overwrite="no"
                       BinaryKey="MyRootCABinary"/>
     </Component>

The certificate is successfully installed on the machine after installation. Now, how do I log the message about this operation?

I am executing below command, and it generates log file

  msiexec /i installer.msi /L*vx c:\work\Test2.log /q 

How do I add, custom messages to this log file? I would like to add a success message for adding a certificate to the system

I am trying to add custom action

  <CustomAction Id="CA.LogCertificateInstallation"
                BinaryKey="BI.CA"
                DllEntry="LogCertificateInstallation"
                Execute="deferred"
                Return="check"
                Impersonate="no"/>

How do I link this custom action to above Component?

Upvotes: 1

Views: 1540

Answers (1)

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

Reputation: 42136

Vital: You can make a setup fail if a vital file is not correctly installed by setting the Vital attribute to yes in WiX in this fashion:

<File Source="MyFile.exe" Vital="yes" />

"If the installation of a file with the msidbFileAttributesVital attribute fails, the installation stops and is rolled back". FileTable - see "Attributes" section.


Default Logging: I don't use the IIS / Certificate element regularly, but I would be very surprised if it didn't do any logging. I would try to read the log again. That log command should do, please check more on logging (section: "Interpreting MSI Log Files").

Custom Logging: This document from Robert Dickau shows valid custom action code for any tool that can create MSI custom actions. He shows VBScript, C++ and Installscript custom actions. I don't have any sample code for C#, but the WiX custom action templates do.

WiX CA Project: WiX Quick Start Links (including downloads). In Visual Studio, go to "Add new project..." and select "C# Custom Action Project for WiX v3". The entry looks something like this:

C# custom action

Once you have the Custom Action project, the logging code is something like this:

public class CustomActions
{
    [CustomAction]
    public static ActionResult CustomAction1(Session session)
    {
        session.Log("Begin CustomAction1");
        return ActionResult.Success;
    }
}

Upvotes: 1

Related Questions