2012-06-28 31 views
1

我有下面的代碼,但是我雖然在BeforeInstall訪問屬性和檢索值部署:this.Context.Parameters沒有提供整個安裝過程

this.Context.Parameters["SERVICENAME"] 

,在OnCommitted相同屬性返回「」。

哪裏這個數據去,它是如何被清空,在哪裏可以找到每一種方法和什麼的秩序崩潰被傳遞在哪裏?

[RunInstaller(true)] 
    public partial class ProjectInstaller : System.Configuration.Install.Installer 
    { 

     public string ServiceName { get; protected set; } 

     /// <summary> 
     /// 
     /// </summary> 
     public ProjectInstaller() 
     { 
      InitializeComponent(); 
     } 

     /// <summary> 
     /// 
     /// </summary> 
     /// <param name="savedState"></param> 
     protected override void OnBeforeInstall(IDictionary savedState) 
     { 
      base.OnBeforeInstall(savedState); 
      this.ServiceName = this.Context.Parameters["SERVICENAME"].ToString(); 
      this.serviceInstaller1.ServiceName = this.ServiceName; 
      this.serviceInstaller1.DisplayName = this.ServiceName; 
     } 

     /// <summary> 
     ////
     /// </summary> 
     /// <param name="savedState"></param> 
     protected override void OnCommitted(IDictionary savedState) 
     { 
      base.OnCommitted(savedState); 
      string targetDirectory = Path.GetDirectoryName(Context.Parameters["AssemblyPath"]); ; 
      string path = System.IO.Path.Combine(targetDirectory, "Services.Win32.exe.config"); 
      System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument(); 
      xDoc.Load(path); 
      System.Xml.XmlNode node = xDoc.SelectSingleNode("/configuration/applicationSettings/Services.Win32.Properties.Settings/setting[@name='TaskManagerServiceName']/value"); 
      node.InnerText = (this.ServiceName); // here this.ServiceName is "" so was this.Context.Parameters[""SERVICENAME"] when i was using that 
      xDoc.Save(path); 
     } 

回答

1

最簡單,最乾淨和最健壯的解決方案是不使用安裝程序類自定義操作來安裝服務。使用內置mechansim的Windows Installer:ServiceInstall表。

問題是你有可能使用不公開此功能的Visual Studio部署項目。沒問題。使用Windows Installer XML來創建封裝XE/Service組件的合併模塊。然後將此合併模塊添加到您的VDPROJ安裝程序。

見的想法在下面的文章怎麼這樣組裝起來:

Augmenting InstallShield using Windows Installer XML - Certificates

Augmenting InstallShield using Windows Installer XML - Windows Services

Redemption of Visual Studio Deployment Projects

3

我碰上了這個問題,試圖附加參數添加到現有的部署時,項目。參數已傳遞給安裝程序,但在Context.Parameters中不可見。事實證明,需要訪問的參數需要添加到該自定義操作的「自定義操作數據」中。

你可以做到這一點通過右擊.vdproj項目,並選擇「查看 - >自定義操作」。從那裏你可以找到你的自定義動作的主要輸出。通過在所需的步驟(安裝,提交,回滾或卸載)中右鍵單擊主要輸出並選擇屬性,您可以編輯該步驟的「自定義操作數據」。你可以找到該屬性的格式here

希望這將節省時間的人,因爲我花了相當長的一段時間才能體現這一點。

相關問題