wixwindows-installercustom-action

WiX/MSI: Redirect stdout to file, type 50 custom action


I have a WiX installer all rigged up to run SqlPackage.exe to deploy some installed .dacpac-packaged SQL applications to a database. Actually deploying the database files as follows will succeed:

<Property Id="CONNSTRING" Value="Data Source=localhost;Integrated Security=True;Initial Catalog=MPQS-DACPAC" />
<Property Id="SQLPACKAGEPATH" Value="C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" />
<CustomAction Id="DeployDatabase" Property="SQLPACKAGEPATH"
              ExeCommand='/Action:Publish /tcs:"[CONNSTRING]" /sf:"[#My.Database.dacpac]" /p:BackupDatabaseBeforeChanges=True /p:RegisterDataTierApplication=True'
              Return="check" Execute="deferred" Impersonate="yes" />

<InstallExecuteSequence>
  <Custom Action="DeployDatabase" After="DuplicateFiles">NOT REMOVE</Custom>
</InstallExecuteSequence>

...and I can watch the output in the presented console window, mid-install.

However, it doesn't always succeed; for example, CONNSTRING can be specified in a dialog and may be incorrect. If there are errors, they appear for an instant, then the console closes and I get a 1722 error in the logs.

To capture the console output, I have tried:

<CustomAction Id="DeployDatabase" Property="SQLPACKAGEPATH"
              ExeCommand='/Action:Publish /tcs:"[CONNSTRING]" /sf:"[#My.Database.dacpac]" /p:BackupDatabaseBeforeChanges=True /p:RegisterDataTierApplication=True &gt; "[DBLogs]test.log"'
              Return="check" Execute="deferred" Impersonate="yes" />

The &gt; "[DBLogs]test.log" on the end should (theoretically) redirect output to a file at that location, but instead, the installer fails out at the moment the console window is shown. It appears that no text is displayed in the console in the instant it is presented.

The kicker is: I can copy the command that is logged with the error (with the &gt; properly resolved to >), paste it into my own cmd window, and it will execute and log.

What am I doing wrong?

And more importantly: what can I do to execute this command and save stdout+stderr to a logfile?

Note: I have also tried this with the type 34 syntax (this way resolves to a type 50). Both exhibit the same behavior.


Solution

  • EXE custom actions have a number of concerns. Read:

    Integration Hurdles for EXE Custom Actions

    To address several of these issues, including stderr/stdout, Wix includes the Quiet Execution Custom Action.