WiX/MSI:将标准输出重定向到文件,键入50自定义操作

WiX/MSI:将标准输出重定向到文件,键入50自定义操作,wix,windows-installer,custom-action,Wix,Windows Installer,Custom Action,我有一个WiX安装程序,所有的安装程序都是为了运行SqlPackage.exe,将一些已安装的.dacpac打包的SQL应用程序部署到数据库中。按如下方式实际部署数据库文件将成功: <Property Id="CONNSTRING" Value="Data Source=localhost;Integrated Security=True;Initial Catalog=MPQS-DACPAC" /> <Property Id="SQLPACKAGEPATH" Value="C

我有一个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>
最后的
“[DBLogs]test.log”
应该(理论上)将输出重定向到该位置的文件,但是安装程序在显示控制台窗口时失败。在显示文本的瞬间,控制台中似乎没有显示任何文本

关键是:我可以复制记录有错误的命令(将
正确解析为
),将其粘贴到我自己的
cmd
窗口中,然后执行并记录

我做错了什么

更重要的是:如何执行此命令并将
stdout
+
stderr
保存到日志文件


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

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


为了解决其中几个问题,包括stderr/stdout,Wix包含了。

我相信SQLPackage.exe中有一些东西,它以非标准方式路由输出(标准和错误)。我在从PowerShell运行SQLPackage.exe时遇到了困难,也遇到了困难。无论我做了什么,我都无法让PowerShell从SQLPackage.exe捕获输出。通过使用Start Process cmdlet而不是Invoke Expression来运行SQLPackage.exe,并传入-RedirectStandardOutput$out和-RedirectStandardError$errorLog,我最终解决了这个问题。通过这种方式,我至少能够捕获输出,但我确实注意到,即使发生错误,它也不会随着错误重定向一起重定向,而是重定向到标准输出流。我不知道为什么会发生这种情况,但这似乎与您在WiX中的结果有关


我想了解更多关于如何将SQLPackage合并到WiX安装中的信息。您是否有任何可以共享的进一步信息,或者您如何处理此问题的资源?

我遇到了相同的问题,我想在WIX MSI安装期间记录SqlPackage.exe的输出,因此我创建了一个WIX二进制扩展名,用于处理获取标准输出/错误并将其记录到SqlPackage.exe的文件中

请点击查看

我让它免费开放源码

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

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


A注意:我最初尝试将重定向操作符作为命令的一部分(即
“[#my.exe]”/args 1>out.log 2>&1
),但CAQuietExec失败,日志中出现了
CAQuietExec:**无法识别的命令行参数“1>。
。删除重定向后,我看到CAQuietExec将日志记录到MSI日志文件中,这对我来说很好。嗨,Paul--IIRC,我要么放弃了,要么WiX自动捕获了输出。:/我会努力挖掘那个项目,看看我发现了什么。很好!谢谢你的建议-我会删除我以前的评论,然后删除这一条,这样你的答案就干净了。干杯
<!-- 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"
/>