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

标签 c# deployment windows-installer

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

 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/

相关文章:

c# - 使用 FlipView 进行缩放的简单相册

c# - 数学表达式生成最好不使用堆栈或队列

firebase - Firebase Web 应用程序上的不同环境

.net - 启动部署的我的应用程序会出现 “has stopped working”错误。我该如何调试?

C# SQLite : Do I need to deploy System. Data.SQLite.xml?

python - 使用 GAE 部署到 PROD 个人域

c# - 微星 : How to retrieve who installed product?

wix - 控制 WIX 功能安装/卸载顺序

wix - 微星 : How a Service is stopped on uninstall during InstallValidate - could that work anyway?

c# - 将背景颜色设置为 DotNet.Highcharts