簡體   English   中英

WiX自定義操作以按鈕開頭

[英]WiX Custom Action start with Button

我有一個自定義操作來檢查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 =“ deferred”更改為Execute =“ immediate”並添加一個按鈕:

        <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為“ true”

我在Visual Studio 2013中使用WIX3.10

我不確定自己在做什么錯。 但是我認為這是InstallExecuteSequence的問題。

我希望有人可以幫助我,謝謝

立即執行是正確的做法,因為您不能在UI序列中延遲自定義操作(因此,您懷疑執行序列不會有問題)。

除此之外,如果代碼開始並且失敗,那么這就是編碼/環境問題。 在此調試階段,您應該只在代碼中放入消息框調用,檢查是否具有值,並且當然可以做更多的事情,以免嘗試/捕獲該異常! 您要問的是在丟棄錯誤並返回失敗結果的同時錯誤可能是什么。

謝謝,您說對了,執行順序不是問題。

我已經解決了問題。 當我不使用CustomActionData時,將執行自定義操作

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

為什么我不能轉讓價值?

更新:

該命令在這里不起作用:

session.CustomActionData("USERNAME")

使用以下命令可以正常工作:

session("USERNAME")

無法使用立即的自定義操作訪問CustomActionData。

但是您可以使用會話直接訪問屬性。

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM