2014-10-06 86 views
0

我有一個使用CAQuietExec的自定義操作,在某些情況下失敗 - 唯一的錯誤消息出現在日誌文件中,這對開發人員來說是非常好的,對最終用戶無用。我的目標是在回滾安裝之前捕獲失敗的操作並預設標準錯誤消息。Wix CustomAction dll

要做到這一點,基於我的研究,我決定我需要編寫自己的自定義動作DLL,所以我開始關注this tutorial。在這個階段,我的dll只記錄一條測試消息並嘗試將錯誤消息傳回對話屏幕。但是,當我編譯並運行msi時,根本沒有任何反應 - 沒有記錄,也沒有任何錯誤消息。看看Orca中的msi,它對我來說看起來不錯 - 但正如你可以在下面看到的那樣,測試dll應該會導致安裝在實際運行時立即中止,而不會立即中止。

所以我的問題:我是否會以最好的方式向用戶提供反饋?如果是這樣,任何想法爲什麼我的自定義操作沒有運行?

感謝

CustomAction.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Deployment.WindowsInstaller; 
using System.Collections.ObjectModel; 
using System.Management.Automation; 

namespace MyCustomActions 
{ 
public class CustomActions 
{ 
    [CustomAction] 
    public static ActionResult CustomAction1(Session session) 
    { 
     session.Log("Begin CustomAction1"); 

     DisplayMSIError(session, "A test message"); 

     return ActionResult.Failure; 
    } 

    static void DisplayMSIError(Session session, String msg) 
    { 
     var r = new Record(); 
     r.SetString(0, msg); 
     session.Message(InstallMessage.Error, r); 
    } 
} 
} 

Product.wxs

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
<Product Id="*" Name="MyPackage" Language="1033" Version="0.0.0.1" Manufacturer="Acme" UpgradeCode="GUID"> 
<Package InstallerVersion="300" Compressed="yes" InstallScope="perMachine" /> 

<Binary Id="MyCustomActions.CA.dll" src="MyCustomActions\MyCustomActions.CA.dll" /> 

<CustomAction Id="MyCustomActionsTest" 
    Return="check" 
    Execute="immediate" 
    BinaryKey="MyCustomActions.CA.dll" 
    DllEntry="CustomAction1" /> 

<InstallExecuteSequence> 
    <Custom Action="MyCustomActionsTest" After="LaunchConditions" /> 
    ... 
</InstallExecuteSequence> 
</Product> 
</Wix> 

回答

0

這個唉,我已經浪費了時間。但任何人誰是有我會同樣的問題用自定義操作發佈我的問題的答案 - 希望它可以節省您的時間和挫折感。

我把我的測試行動很早的序列,認爲我會看到錯誤消息對話框。因此,我實際上沒有試圖通過安裝 - 當歡迎對話出現時,我認爲我的操作沒有運行。但是,它必須已運行,因爲實際選擇某個功能並允許安裝進行時,會顯示錯誤消息。

不過,如果任何人都可以提供一些見解,如果這是從CAQuietExec以其他方式正常運行的操作中給出用戶反饋的最佳方式,那將值得讚賞。

+1

我想,也許你只是需要多一點理解的方式失速作品。其中一個重要思想是你遇到的一個問題:InstallUISequence先運行,然後執行序列,所以你的CA在標準的UI對話框之後。 session.message沒有錯誤告訴用戶錯誤。 – PhilDW 2014-10-06 17:10:29

0

,你怎麼看待這個解決方案:

 Record record = new Record(); 
     record.FormatString = string.Format("Something has gone wrong!"); 

     session.Message(
     InstallMessage.Error | (InstallMessage) (MessageBoxIcon.Error) | 
     (InstallMessage) MessageBoxButtons.OK, 
     record); 

this answer

另一種方式 - 是創建自己的UI,當你想要顯示的任何消息。 小例子:

自定義操作:

[CustomAction] 
    public static ActionResult CheckSqlSessionState(Session session) 
    { 
     try 
     { 
      session.SendMessage(InstallMessage.Info, "Check Sql Session State"); 

      return ActionResult.Success; 
     } 
     catch (Exception exception) 
     { 
      session.SendMessage(InstallMessage.Error, 
       string.Format("Error during the cheking sesssion state. {0}", exception.Message)); 
      return ActionResult.Failure; 
     } 
    } 

註冊:

<CustomAction Id="WiXSetup.CustomAction.CheckSqlSessionState" 
      BinaryKey="WiXSetup.CustomActions.dll" 
      DllEntry="CheckSqlSessionState" Execute="deferred" /> 

    <CustomAction Id="SetCheckSqlSessionStateDataValue" 
      Return="check" 
      Property="WiXSetup.CustomAction.CheckSqlSessionState" /> 

    <InstallExecuteSequence> 
     <Custom Action="SetCheckSqlSessionStateDataValue" Before="WiXSetup.CustomAction.CheckSqlSessionState">NOT Installed</Custom> 
     <Custom Action="WiXSetup.CustomAction.CheckSqlSessionState" After="WiXSetup.CustomAction.UpdateHomePageUrls">NOT Installed</Custom> 
    </InstallExecuteSequence> 

CSHARP UI:

using Microsoft.Deployment.WindowsInstaller; 

    private ExternalUIRecordHandler recordHandler; 
    // ... 

    IntPtr parent = IntPtr.Zero; 

    recordHandler = RecordHandler; 

    private MessageResult RecordHandler(InstallMessage messageType, Record messageRecord, MessageButtons buttons, MessageIcon icon, MessageDefaultButton defaultButton) 
    { 
     switch (messageType) 
     { 
      case InstallMessage.Info: 
       log.Info(message); 
       return MessageResult.OK; 
      case InstallMessage.Initialize: 
       log.Debug(message); 
       return MessageResult.OK; 
      case InstallMessage.ActionData: 
       log.Debug(message); 
       return MessageResult.OK; 
      case InstallMessage.ActionStart: 
       log.Debug(message); 
       return MessageResult.OK; 
      case InstallMessage.CommonData: 
       return MessageResult.OK; 
      case InstallMessage.Error: 
       log.Error(message); 
       return MessageResult.OK; 
      case InstallMessage.FatalExit: 
       log.Fatal(message); 
       return MessageResult.OK; 
      case InstallMessage.FilesInUse: 
       return MessageResult.No; 
      case InstallMessage.OutOfDiskSpace: 
       break; 
      case InstallMessage.Progress: 
       return MessageResult.OK; 
      case InstallMessage.ResolveSource: 
       return MessageResult.No; 
      case InstallMessage.ShowDialog: 
       return MessageResult.OK; 
      case InstallMessage.Terminate: 
       return MessageResult.OK; 
      case InstallMessage.User: 
       return MessageResult.OK; 
      case InstallMessage.Warning: 
       log.Warn(message); 
       return MessageResult.OK; 
     } 

     return MessageResult.No; 
    } 
+0

我想我的擔心更多的是,似乎總是矯枉過正,不得不重新創建一個動作作爲一個DLL,因爲我無法弄清楚如果一個CAQuietExec操作失敗如何給出一個很好的錯誤消息。正如我目前的安裝 - 如果操作失敗,用戶只能看到安裝程序提供的通用「出錯的信息」。我對通用消息完全沒問題,但是我想指定我自己的字符串,因爲我可以讓用戶更好地瞭解問題所在。 – 2014-10-06 20:03:47

相關問題