2010-06-29 90 views
0

我使用VS2010和WIX 3.5。WIX c#CustomAction,我做錯了什麼?

1)我創建了WIX Setup Project。

2)然後我加入到溶液C#自定義操作項目,並把它稱爲「CustomActions」

namespace CustomActions 
{ 
    public static class CustomActions 
    { 
    [CustomAction] 
    public static ActionResult CustomAction1(Session session) 
    { 
     Debugger.Break(); 
     MessageBox.Show("It works"); 
     session.Log("Begin CustomAction1"); 
     return ActionResult.Success; 
    } 
    } 
} 

3)然後我編譯CustomActions項目,並從我的安裝項目添加引用。

4)最後放入.wxs文件:

<Binary Id="CustomActions" SourceFile="$(var.CustomActions.TargetDir)$(var.CustomActions.TargetName).CA.dll"/> 

<CustomAction Id="CustomAction1" BinaryKey="CustomActions" DllEntry="CustomAction1" Execute="immediate" /> 

這是行不通的。我究竟做錯了什麼?請幫幫我。

回答

1

您還需要安排的自定義操作運行

<InstallUISequence> 
     <Custom Action="CustomAction1" After="AppSearch"/> 
    </InstallUISequence> 

而且你要知道,在MSI沙盒限制了很多東西運行。我不相信你對MessageBox.Show的調用會起作用。你將不得不依靠會話記錄來代替。

+0

對MessageBox.Show()的調用將工作,如果他引用名稱空間System.Windows.Forms並且還添加了指令'Using System.Windows.Forms' – Mario 2010-07-07 21:07:43

+0

我給它一個測試,它確實看起來似乎上班。我不相信它是一個好主意,但是它能完成任務。 :) – 2010-07-07 22:32:43

+0

你應該使用session.Message來顯示一條消息,否則你不能保證消息框會在最前面,而不需要更多的編碼 – 2011-06-21 04:19:30