3

我有一个 WiX 安装程序,所有安装程序都可以运行SqlPackage.exe以将一些已安装.dacpac的打包 SQL 应用程序部署到数据库。实际上如下部署数据库文件会成功:

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

...我可以在安装过程中看到显示的控制台窗口中的输出。

但是,它并不总是成功。例如,CONNSTRING可以在对话框中指定,但可能不正确。如果有错误,它们会立即出现,然后控制台关闭,我在日志中收到 1722 错误。

为了捕获控制台输出,我尝试过:

<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" />

最后&gt; "[DBLogs]test.log"应该(理论上)将输出重定向到该位置的文件,但相反,安装程序在显示控制台窗口时失败。似乎在显示的那一刻,控制台中没有显示任何文本。

踢球者是:我可以复制记录错误的命令(&gt;正确解析为>),将其粘贴到我自己的cmd窗口中,它将执行并记录。

我究竟做错了什么?

更重要的是:我能做些什么来执行这个命令并将stdout+保存stderr到日志文件中?

注意:我也尝试过使用 type 34 语法(这种方式解析为 type 50)。两者都表现出相同的行为。

4

3 回答 3

1

EXE 自定义操作有许多问题。读:

EXE 自定义操作的集成障碍

为了解决其中的几个问题,包括 stderr/stdout,Wix 包含了Quiet Execution Custom Action

于 2013-06-05T12:49:37.117 回答
1

我有同样的问题,我想在 WIX MSI 安装期间记录 SqlPackage.exe 的输出,所以我创建了一个 WIX 二进制扩展来处理获取标准输出/错误并将其记录到 sqlpackage.exe 的文件中。

在https://wixdacpacinstaller.codeplex.com/上查看。

我使它免费和开源。

文档中的快速片段显示如何使用它:

<!-- 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"
/>
于 2016-03-01T16:33:11.347 回答
0

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?

于 2014-01-03T17:14:11.727 回答