部署:this.Context.Parameters在整个安装过程中不可用 [英] Deployment: this.Context.Parameters not available throughout installation process

查看:269
本文介绍了部署:this.Context.Parameters在整个安装过程中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following code but although I can access a property and retrieve a value

 this.Context.Parameters["SERVICENAME"] 

中,相同的属性在OnCommitted中返回。

in BeforeInstall, the same property returns "" in OnCommitted.

这些数据在哪里,如何擦除,在哪里可以找到每种方法的顺序明细,什么传递到哪里?

Where does this data go, how does it gets wiped, where can I find a breakdown of the order of each of these methods and what gets passed where?

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


推荐答案

最简单,最干净,最可靠的解决方案是不使用安装程序类自定义操作来安装服务。请使用Windows Installer内置的机制: ServiceInstall 表。

The easiest, cleanest and most robust solution is to not use an installer class custom action to install a service. Use Windows Installer's built in mechansim: the ServiceInstall table.

问题是您可能正在使用未公开此功能的Visual Studio部署项目。

The problem is you are likely using Visual Studio Deployment Projects which don't expose this capability. No problem. Use Windows Installer XML to author a Merge Module that encapsulates your XE/Service component. Then add this merge module to your VDPROJ installer.

请参阅以下文章,以获取有关如何封装XE / Service组件的合并模块的信息,然后将其添加到VDPROJ安装程序中。连线:

See the following articles for ideas on how to wire this up:

八月使用Windows Installer XML-证书

使用Windows Installer XML增强InstallShield-Windows服务

赎回Visual Studio部署项目

这篇关于部署:this.Context.Parameters在整个安装过程中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆