Question

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.

Était-ce utile?

La 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.

Autres conseils

I have had the same problem where I wanted to log the output of SqlPackage.exe during a WIX MSI Install, so I created a WIX binary extension that handles getting the standard output/error and logging it to a file for sqlpackage.exe.

Check it out at https://wixdacpacinstaller.codeplex.com/.

I made it free and open source.

Quick Snippet from the docs to show how to use it:

<!-- first, add the binary extension.  Be sure to specify the source file as WixDacPacExtension.CA.dll. -->
<Binary
     Id="WixDacPacExtensionBinary"
     SourceFile="<Path to your file>\WixDacPacExtension.CA.dll"/>

<!-- Create a custom action to run first and set up all the parameters that are -->
<!-- passed to the Wix DacPac Extension.  The property name MUST MATCH -->
<!-- the name of the custom action that executes the binary defined above. -->
<!-- The parameters in the Value property are semi-colon delimited. -->
<CustomAction
     Id="SetupDacPacWIXDacPacInstallerExampleCustomAction"
     Property="DacPacWIXDacPacInstallerExampleCustomAction" 
     Value="ShowUI=True;SqlPackagePath=c:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe;DacPacPath=[INSTALLFOLDER]WIXDacPacInstallerExample.dacpac;LogFilePath=[TempFolder]\WIXDacPacInstallerExample.dacpac.log;TargetServerName=[DATABASESERVER];TargetDatabaseName=WIXDacPacInstallerExample;OtherParameters=/p:RegisterDataTierApplication=True /p:BlockWhenDriftDetected=False /p:BlockOnPossibleDataLoss=False"
        />

<!-- 
     This custom action will execute the extension with the parameters from Step #1.
     NOTE: the Id of this custom action matches the Property of the custom action
          from Step #1.
-->
<CustomAction
     Id="DacPacWIXDacPacInstallerExampleCustomAction"
     BinaryKey="WixDacPacExtensionBinary"
     DllEntry="Execute"
     Execute="deferred"
     Return="check"
/>

I believe there is something about SQLPackage.exe which routes the output (both standard and error) in a non-standard way. I encountered difficulties when running SQLPackage.exe from PowerShell and also had difficulties. No matter what I did, I could not get PowerShell to capture the output from SQLPackage.exe. Ultimately I was able to resolve the problem by using Start-Process cmdlet instead of Invoke-Expression to run SQLPackage.exe, and pass in -RedirectStandardOutput $out and -RedirectStandardError $errorLog. In this way I was at least able to capture the output, but I did notice that even when an error occurred, it wasn't redirected along with the Error redirect, but rather it was redirected to the standard output stream. I don't know exactly why this happens, but it seems like this would be relevant to the results you had in WiX.

I would love to see more about how you were able to incorporate SQLPackage into a WiX installation. Do you have any further information you can share, or resources on how you approached this?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top