1

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?

kudlatiger
  • 2,355
  • 3
  • 30
  • 67
  • [A quick link for now](https://resources.flexera.com/web/pdf/archive/msi_writing_to_the_log_file.pdf). I have answer on this before, you could try searching for it (heading out right now). – Stein Åsmul Nov 26 '19 at 09:03
  • Is this link valid for c#/Visual studio? – kudlatiger Nov 26 '19 at 09:48
  • Those samples are valid for any tool that can create MSI custom actions. I don't have any sample code for C#, but the WiX custom action templates do. In Visual Studio, go to *"Add new project..."* and select *"C# Custom Action Project for WiX v3"*. The code is something like: `session.Log("Begin CustomAction1");` – Stein Åsmul Nov 26 '19 at 13:45
  • How do I link this custom action to above Component? – kudlatiger Nov 27 '19 at 02:34
  • Did you see my suggestion below to use the "Vital" flag? That would probably be enough, hence eliminating unwanted complexity. – Stein Åsmul Dec 02 '19 at 23:27
  • yes, works great! – kudlatiger Dec 03 '19 at 04:41
  • 1
    Cool, I didn't remember that setting at first. Just wanted to make sure you got the message. So much easier. – Stein Åsmul Dec 03 '19 at 10:50

1 Answers1

1

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;
    }
}
Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140
  • what if Component Id="MyRootCA.cer" fails? I am not able to connect the information. – kudlatiger Nov 27 '19 at 08:29
  • 1
    Did you try to set the file vital? ``. *"If the installation of a file with the `msidbFileAttributesVital` attribute fails, the installation stops and is rolled back"*. [FileTable](https://docs.microsoft.com/en-us/windows/win32/msi/file-table) - see "Attributes" section. – Stein Åsmul Nov 28 '19 at 12:24