2013-10-27 22 views
1

我有簡單的維克斯(Microsoft.Deployment.WindowsInstaller)的自定義操作:如何將使用InstallShield的'Session'參數傳遞給我的WiX自定義操作?

[CustomAction] 
    public static ActionResult TestDtf(Session session) 
    { 
     MessageBox.Show("Test"); 

     ActionResult result = ActionResult.Success; 
     return result; 

    } 

我需要有我創建使用InstallShield稱此爲遞延/系統環境自定義操作,所以我怎麼設置的方法簽名參數,以便它發送會話? 'Session'基本上是Msi句柄嗎?我已經使用「MSIHANDLE」價值試過了,但是這將導致錯誤:

InstallShield: Deferred action requested property MsiHiddenProperties not provided by CustomActionData 
InstallShield: Loading assembly Test.Installation.CustomActions from resource 4098 
InstallShield: Loading Assembly Microsoft.Deployment.WindowsInstaller 
InstallShield: Unexpected parameter type Microsoft.Deployment.WindowsInstaller.Session encountered; passing string instead 
InstallShield: Calling method with parameters [(System.String)294] 
InstallShield: Exception: System.ArgumentException: Object of type 'System.String' cannot be converted to type 'Microsoft.Deployment.WindowsInstaller.Session'. 
    at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) 
    at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) 
    at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) 
    at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
    at InstallShield.ClrHelper.CustomActionHelper.CallMethod(EntryPointInfo info) 

回答

1

你不因爲你不需要。您正在InstallShield中創建錯誤的自定義操作。假裝你的DLL不是.NET,因爲就DTF而言,事實並非如此。它已被封裝爲本地DLL。

1

這個問題對我的答案是改變我添加到MSI DLL的DLL CA的類型。然後它只會詢問函數名稱而不是參數和返回值。不幸的是,我無法在網上找到這個解釋,並且花了一些猜測。這是你的方法簽名應該看起來像什麼。

[CustomAction] 
    public static ActionResult VerifyCA(Session session) 
    { 
    //Record record = new Record(2); 
    //record[0] = "[1]"; 
    //record[1] = "Testing Wix message"; 
    //session.Message(InstallMessage.Error, record); 

    return ActionResult.Failure; 
    } 

選擇合適的CA類型後,它的工作原理是由2009年的Installshield希望爲我的魅力這可以幫助別人。

+0

DTF在我的博客上有詳細解釋。 –

0

我的回答是w.r.t. Installshiled 2016,在所有可能的情況下,它必須在早期的installshield版本中以相同的方式工作,但我沒有驗證相同。

是的。內置的MsiHandle varible是安裝過程中的會話,但它需要額外的一行代碼才能在C#端獲得。我能夠在我通過託管自定義操作調用的.Net程序集中實現它。代碼如下:

//import this namespace at the top of your *.cs file 
using Microsoft.Deployment.WindowsInstaller; 

public static int MakeChangesInCurrentInstallSession(IntPtr hMsi) 
{ 
    Session session = Session.FromHandle(hMsi, false); 

    view = session.Database.OpenView("SELECT * FROM ComboBox"); 
    view.Execute(); 
    //do other things whatever you want to do in the installer session 
    //Record record = session.Database.CreateRecord(4); 
    //view.Modify(....); 
    //..... 
    //return success if everything went well 
    return (int)ActionResult.Success; 
} 

如果你讓你的方法的簽名如下圖所示,並試圖從你的託管自定義操作調用它:

public static int MakeChangesInCurrentInstallSession(Session hMsi) 

然後,你所面臨的鑄造如下錯誤:

InstallShield: Unexpected parameter type Microsoft.Deployment.WindowsInstaller.Session encountered; passing string instead

注意:對於上面的代碼工作,你將有來自外部的C#項目添加引用Microsoft.Deployment.WindowsInstaller.dll ensions選項卡在添加參考窗口中。此外,由於此程序集不是.Net框架的一部分,因此您必須將此程序集作爲依賴項添加到installshield執行順序的託管自定義操作中,詳細信息請參見here

相關問題