WiX自定义操作以Button开头

时间:2015-10-28 16:02:20

标签: vb.net wix custom-action

我有一个自定义操作来检查SQL连接。 现在,它应该使用控制按钮,但这不起作用。

自定义操作在没有按钮的情况下运行良好: 这里是wxs-File:

<?xml version="1.0" encoding="UTF-8"?>

    

<Property Id="SERVERNAME" Value="MSSQL2008R2" />
<Property Id="DATABASENAME" Value="MyDatabase" />
<Property Id="USERNAME" Value="admin" />
<Property Id="PASSWORD" Value="mypassword" />

<Binary Id="CA_SQLTestDLL" SourceFile="$(var.CA_SQLConnectionTest.TargetDir)CA_SQLConnectionTest.CA.dll" />
<CustomAction Id="SQL_Test"
              BinaryKey="CA_SQLTestDLL"
              DllEntry="ConnectionTest"
              Execute="deferred"
              Return="check" />
<SetProperty Id="SQL_Test" Value="SERVERNAME=[SERVERNAME];DATABASENAME=[DATABASENAME];USERNAME=[USERNAME];PASSWORD=[PASSWORD]" Sequence="execute" Before="SQL_Test" />

<InstallExecuteSequence>
  <Custom Action="SQL_Test" After="InstallInitialize" />
</InstallExecuteSequence>


<UI>
  <Dialog Id="SQLServerConnectionTestDlg" Width="370" Height="270" Title="SQL Server connection test">
    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" />
    <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
  </Dialog>
</UI>

这是我的CustomAction类:

Imports System.Data
Imports System.Data.SqlClient
Public Class CustomActions
<CustomAction()> _
Public Shared Function ConnectionTest(ByVal session As Session) As ActionResult
session.Log("############## Begin CUSTOMACTION ##############")
Dim userName As String
Dim password As String
Dim serverName As String
Dim dataBase As String

serverName = session.CustomActionData("SERVERNAME")
dataBase = session.CustomActionData("DATABASENAME")
userName = session.CustomActionData("USERNAME")
password = session.CustomActionData("PASSWORD")

Dim SqlConn As New SqlConnection
Dim SqlConnStr As String = "Data Source=" + serverName + ";Database=" + dataBase + ";Persist Security Info=True;User ID=" + userName + ";Password=" + password

If SqlConn.State = ConnectionState.Closed Then
  SqlConn.ConnectionString = SqlConnStr
  Try
    SqlConn.Open()
  Catch ex As Exception
    Return ActionResult.Failure
  End Try
End If
session.Log("### SUCCESSFULL ###")
Return ActionResult.Success
  End Function

End Class

install.log:

Calling custom action CA_SQLConnectionTest!CA_SQLConnectionTest.CustomActions.ConnectionTest
############## Begin CUSTOMACTION ##############
### SUCCESSFULL ###

现在,我想用按钮启动自定义操作。 所以我必须改变Execute =&#34; deferred&#34;执行=&#34;立即&#34;并添加一个按钮:

        <Control Id="TestConn" Type="PushButton" X="265" Y="205" Width="70" Height="18" Text="&amp;Test Connection">
      <Publish Event="DoAction" Value="SQL_Test">1</Publish>
      <Publish Property="ERRORMSG" Value="ConnectionTest">ACCEPTED = "1"</Publish>
      <Publish Event="SpawnDialog" Value="InvalidDBConnDlg">ACCEPTED = "0"</Publish>
    </Control>

      <Dialog Id="InvalidDBConnDlg" Width="260" Height="120" Title="MyTester">
    <Control Id="OK" Type="PushButton" X="102" Y="90" Width="56" Height="17" Default="yes" Cancel="yes" Text="OK">
      <Publish Event="EndDialog" Value="Exit" />
    </Control>
    <Control Id="Text" Type="Text" X="48" Y="22" Width="194" Height="60" Text="FAILED" />
    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="WixUI_Ico_Info" />
  </Dialog>

现在,当我按下按钮时,设置会被设置,并且我在日志文件中出现致命错误:

Action 16:43:20: SQL_Test. 
Action start 16:43:20: SQL_Test.
MSI (c) (5C:5C) [16:43:20:236]: Invoking remote custom action. DLL: C:\Users\LOC~1.CRE\AppData\Local\Temp\MSIC08C.tmp, Entrypoint: ConnectionTest
Action ended 16:43:20: SQL_Test. Return value 3.
MSI (c) (5C:20) [16:43:20:404]: Note: 1: 2205 2:  3: Error 
MSI (c) (5C:20) [16:43:20:404]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2896 
DEBUG: Error 2896:  Executing action SQL_Test failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: SQL_Test, , 
Action ended 16:43:20: WelcomeDlg. Return value 3.
MSI (c) (5C:54) [16:43:20:405]: Doing action: FatalError
MSI (c) (5C:54) [16:43:20:405]: Note: 1: 2205 2:  3: ActionText 
Action 16:43:20: FatalError. 
Action start 16:43:20: FatalError.
Action 16:43:20: FatalError. Dialog created
Action ended 16:43:23: FatalError. Return value 2.
Action ended 16:43:23: INSTALL. Return value 3.
MSI (c) (5C:54) [16:43:23:488]: Destroying RemoteAPI object.
MSI (c) (5C:50) [16:43:23:488]: Custom Action Manager thread ending

Config useLegacyV2RuntimeActivationPolicy是&#34; true&#34;

我在Visual Studio 2013中使用WIX3.10

我不确定我做错了什么。但我认为这是InstallExecuteSequence的一个问题。

我希望有人可以帮助我,谢谢

3 个答案:

答案 0 :(得分:0)

正确的做法是正确的,因为您不能在UI序列中使用延迟的自定义操作(因此,您怀疑执行序列不会出现问题)。

除此之外,如果代码启动并且失败则会出现编码/环境问题。您应该在进入此调试阶段时将消息框调用放入代码中,检查您是否拥有这些值,并且确实做了更多的事情,只是通过try / catch来消除任何异常!您在丢弃它并返回失败结果的同时询问错误可能是什么。

答案 1 :(得分:0)

谢谢,你说得对,执行顺序不是问题。

我已经缩小了问题范围。如果我不使用CustomActionData,则可以使用自定义操作

userName = session.CustomActionData("USERNAME")
password = session.CustomActionData("PASSWORD")
...

为什么我无法转移价值?

更新

命令不是&#39;在这里工作:

session.CustomActionData("USERNAME")

使用follow命令工作正常:

session("USERNAME")

答案 2 :(得分:0)

无法通过立即自定义操作访问CustomActionData。

但您可以使用会话直接访问属性。

试试这个

  userName = session["USERNAME"];
  password = session["PASSWORD"];