2009-06-11 31 views

回答

9

我們有相同的場景,它的工作原理。您對傳遞的參數如下

InstallUtil.exe /Param1="Value" /Param2="Value" "Path to your exe" 

,那麼你已經覆蓋你的安裝程序安裝方法

public override void Install(System.Collections.IDictionary stateSaver) 
{ 
    var lParam1 = GetParam("Param1"); 
} 

private string GetParam(string pKey) 
{ 
     try 
     { 
      if (this.Context != null) 
      { 
       if (this.Context.Parameters != null) 
       { 
        string lParamValue = this.Context.Parameters[pKey]; 
        if (lParamValue != null) 
         return lParamValue; 
       } 
      } 
     } 
     catch (Exception) 
     { 
     } 
     return string.Empty; 
    } 
+0

僅供將來參考:如果您通過參數(動態服務創建)傳遞服務名稱,則需要在OnBeforeInstall中獲取參數。謝謝你的回答。 – 2009-06-12 13:36:05

0

嘗試NSIS。這是一種爲安裝而構建的腳本語言,允許您執行各種複雜的事情。就我個人而言,我將它用於超越「下一步,下一步,下一步」的任何安裝。很光滑,並不是所有這些都很難學。

0

構建和安裝Visual Studio或類似Wix。在Visual Studio中,您可以執行Custom Action並在CustomActionData字段中傳入參數。

2

其實它可以與InstallUtil.exe時,.NET安裝實用程序來做到這一點隨.NET Framework一起提供。

看看這個CodeProject文章。

+0

頁面非常差,但源代碼顯示了一些有趣的內容+1。 – 2009-06-12 13:36:37