2010-09-16 79 views
10

我有一個爲x86(32位)和x64(64位)平臺構建的C#應用​​程序。我的構建系統目前輸出兩個MSI安裝程序,每個平臺一個。如果它有所不同,我的C#應用​​程序包含一個Windows任務欄工具欄,這意味着安裝的DLL必須由explorer.exe進程加載。單個MSI安裝正確的32位或64位C#應用程序

是否可以生成一個MSI安裝程序,根據當前操作系統是否是64位操作系統,安裝我的應用程序的正確版本?

目前已經通過使用http://dotnetinstaller.codeplex.com/來生成一個執行體系結構檢查然後啓動正確的MSI的EXE來實現。但是,我更喜歡純粹基於MSI的方法。

+0

相關:[我如何有條件地安裝基於目標機器(32位或64位)的WiX文件?](http://stackoverflow.com/questions/730534/) – 2012-10-05 20:04:05

回答

7

不,這是不可能的。查看Heath Stewart的Different Packages are Required for Different Processor Architectures的帖子。與MSI一起處理這個問題的唯一方法是根據您所描述的方式進行引導。如果您只需要在64位位置放置文件或密鑰,可以(但不推薦)在自定義操作中執行此操作,但更改目標安裝位置並使用內置MSI文件支持會贏得'工作。

+0

+1高度相關的鏈接。 – Brian 2010-09-16 14:28:59

6

你可以解決這個問題。在第三個部署項目下打包2個安裝程序。創建一個自定義操作來檢查正在運行的操作系統版本,然後使安裝程序調用正確的安裝程序。

事情是這樣的:

[RunInstaller(true)] 
public partial class MyInstaller: Installer 
{ 
    String installerPath; 

    public MyInstaller() 
    { 
     InitializeComponent();  
     if (Is64Bit())//running as 64-bit 
     { 
      installerPath= @"installfolder\my64bitsetup.exe"; 
     } 
     else 
     { 
      installerPath= @"installfolder\my32bitsetup.exe"; 
     } 
    } 

    [SecurityPermission(SecurityAction.Demand)] 
    public override void Install(IDictionary stateSaver) 
    { 
     base.Install(stateSaver); 
    } 

    [SecurityPermission(SecurityAction.Demand)] 
    public override void Commit(IDictionary savedState) 
    { 
     base.Commit(savedState); 
     MyInstall(); 
    } 

    [SecurityPermission(SecurityAction.Demand)] 
    public override void Rollback(IDictionary savedState) 
    { 
     base.Rollback(savedState); 
    } 

    [SecurityPermission(SecurityAction.Demand)] 
    public override void Uninstall(IDictionary savedState) 
    { 
     base.Uninstall(savedState); 
     base.Commit(savedState); 
    } 

    private void MyInstall() 
    { 
     ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe", "/c " + installerPath); 
     RunProcess(procStartInfo); 
    } 

    private void RunProcess(ProcessStartInfo procStartInfo) 
    { 
     Process proc = new Process(); 
     proc.StartInfo = procStartInfo; 
     proc.Start(); 
     proc.WaitForExit(); 
    } 

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] 
[return: MarshalAs(UnmanagedType.Bool)] 
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo); 

private bool Is64Bit() 
{ 
    return (IntPtr.Size == 8 || (IntPtr.Size == 4 && Is32BitProcessOn64BitProcessor())); 
} 

private bool Is32BitProcessOn64BitProcessor() 
{ 
    bool retVal; 
    IsWow64Process(Process.GetCurrentProcess().Handle, out retVal); 
    return retVal; 
} 

好吧,那是很久......

總之,在提交你可以肯定的是,安裝已經解包,只要確保你有正確的路徑。 (您可以將cmd命令從/ c更改爲/ k以進行測試,這將保持命令提示符窗口處於活動狀態,以便您看到消息)

您可以閱讀更多關於自定義操作的信息,可以傳遞安裝路徑通過論據。

相關問題