我有以下代码,但虽然我可以访问一个属性并检索一个值
this.Context.Parameters["SERVICENAME"]
在 BeforeInstall 中,相同的属性在 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);
}