2014-04-28 328 views
2

我有一個對話框,它是我的安裝程序的一部分,用於輸入激活密鑰。我能夠從該控件傳遞值,Wix:無法使用自定義操作設置屬性

  <Control Id="KEY1" Type="Edit" Property="KEY1" Height="17" Width="45" X="50" Y="150" Text="{5}" Indirect="no"/> 

我的自定義操作,

session["KEY1"] 

但我似乎無法弄清楚,爲什麼我不能設置會話[「KEY1 「] =」測試「,並看到我的控制中的值...我嘗試了一切,但沒有任何工作。這裏是我當前的代碼,

C#(自定義操作)

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Deployment.WindowsInstaller; 

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

      session["KEY1"] = "lol"; 
      string[] lines = { session["KEY1"], "Second line", "Third line" }; 
      System.IO.File.WriteAllLines(@"C:\CustomAction.txt", lines); 

      return ActionResult.Success; 
     } 
    } 
} 

維克斯

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
    <Property Id="KEY1" Value="Test" Secure="yes"/> 
    <Property Id="Key2"/> 
    <Property Id="Key3"/> 
    <Property Id="Key4"/> 
    <Property Id="Key5"/> 
    <Property Id="Key6"/> 
    <UI> 
     <Dialog Id="ActivationCodeDlg" Width="370" Height="270" Title="!(loc.InstallDirDlg_Title)"> 
     <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)"/> 
     <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}Activation Code"/> 
     <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Please enter your activation code"/> 
     <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0"/> 

     <Control Id="KEY1" Type="Edit" Property="KEY1" Height="17" Width="45" X="50" Y="150" Text="{5}" Indirect="no"/> 
     <Control Id="Hyphen1" Type="Text" Height="17" Width="5" X="96" Y="153" Text="-"/> 
     <Control Id="Key2" Type="Edit" Property="Key2" Height="17" Width="45" X="100" Y="150" Text="{5}"/> 
     <Control Id="Hyphen2" Type="Text" Height="17" Width="5" X="146" Y="153" Text="-"/> 
     <Control Id="Key3" Type="Edit" Property="Key3" Height="17" Width="45" X="150" Y="150" Text="{5}"/> 
     <Control Id="Hyphen3" Type="Text" Height="17" Width="5" X="196" Y="153" Text="-"/> 
     <Control Id="Key4" Type="Edit" Property="Key4" Height="17" Width="45" X="200" Y="150" Text="{5}"/> 
     <Control Id="Hyphen4" Type="Text" Height="17" Width="5" X="246" Y="153" Text="-"/> 
     <Control Id="Key5" Type="Edit" Property="Key5" Height="17" Width="45" X="250" Y="150" Text="{5}"/> 
     <Control Id="Hyphen5" Type="Text" Height="17" Width="5" X="296" Y="153" Text="-"/> 
     <Control Id="Key6" Type="Edit" Property="Key6" Height="17" Width="15" X="300" Y="150" Text="{1}"/> 

     <Control Id="Activate" Type="PushButton" X="50" Y="200" Width="56" Height="17" Text="Activate"> 
      <Publish Event="DoAction" Value="Testing"/> 
     </Control> 

     <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0"/> 
     <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 Id='Testing' BinaryKey='FooBinary' DllEntry='TestAction' Execute='immediate'/> 
    <Binary Id='FooBinary' SourceFile='Feenics.Keep.CustomActions.CA.dll'/> 
    </Fragment> 
</Wix> 
+0

你有什麼錯誤嗎?你在詳細日誌中看到什麼? –

+0

你應該說什麼時候你的自定義動作被調用 - 顯然沒有從該WiX代碼調用它。 – PhilDW

回答

1

哪裏是你的InstallExecuteSequence/InstallUISequence代碼?

<InstallUISequence> 
    <Custom Action="Testing" Sequence="1" /> 
</InstallUISequence> 

也許增加這將使這個自定義操作發生在你的UI對話框被調用之前。

編輯: 另外,您是否已經完成了安裝程序的任何詳細調試(詳細日誌記錄)以檢查發生了什麼以及什麼時候正在運行?在你有.MSI輸出後,打開一個命令提示符並執行:

msiexec.exe /i <yourmsi> /l*vx Output.txt 

這會給你你的東西的詳細輸出!

相關問題