gpt4 book ai didi

c# - 部署:this.Context.Parameters 在整个安装过程中不可用

转载 作者:行者123 更新时间:2023-12-04 00:45:21 25 4
gpt4 key购买 nike

我有以下代码,但尽管我可以访问属性并检索值

 this.Context.Parameters["SERVICENAME"] 

在BeforeInstall 中,相同的属性在OnCommissed 中返回“”。

这些数据去了哪里,如何被删除,在哪里可以找到这些方法的顺序的详细信息以及什么被传递到哪里?

[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);
}

最佳答案

我在尝试向现有部署项目添加其他参数时遇到了这个问题。参数已传递给安装程序,但在 Context.Parameters 中不可见。事实证明,需要将可访问的参数添加到该自定义操作的“自定义操作数据”中。

您可以通过右键单击 .vdproj 项目并选择查看 -> 自定义操作来实现此目的。从那里您可以找到自定义操作的主要输出。通过右键单击所需步骤(安装、提交、回滚或卸载)中的主要输出并选择属性,您可以编辑该步骤的自定义操作数据。您可以找到该属性的格式 here .

希望它能节省某人的时间,因为我花了很长时间才弄清楚这一点。

关于c# - 部署:this.Context.Parameters 在整个安装过程中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11253460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com