none
C# 创建windows服务时无法添加安装程序? RRS feed

  • 问题

  • 跟这个问题一样

    https://social.msdn.microsoft.com/Forums/zh-CN/d53345f4-33d7-4332-862e-d9b4030582eb/windows?forum=visualcshartzhchs

    VS版本测试过2013,2015,2017故障依旧,操作系统使用过win7,win10

    新建一个服务,可以右键添加安装程序,但是发现第二天重启电脑后原来设置好的服务安装又不见了,而且无法添加

    我就想知道这个问题一般是什么原因引起的,如何解决?

    2018年9月6日 8:32

全部回复

  • 你好,

    你可以参考下面文档给出的解决方案,手动添加下面两个分部类。

    #ProjectInstaller.Designer.cs

    partial class ProjectInstaller
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
     
            /// <summary> 
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing &amp;amp;&amp;amp; (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
     
            #region Component Designer generated code
     
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
                this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
                // 
                // serviceProcessInstaller1
                // 
                this.serviceProcessInstaller1.Password = null;
                this.serviceProcessInstaller1.Username = null;
                // 
                // serviceInstaller1
                // 
                this.serviceInstaller1.ServiceName = "CandorWorkerRoleService";
                // 
                // ProjectInstaller
                // 
                this.Installers.AddRange(new System.Configuration.Install.Installer[] {
                this.serviceProcessInstaller1,
                this.serviceInstaller1});
     
            }
     
            #endregion
     
            private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
            private System.ServiceProcess.ServiceInstaller serviceInstaller1;
        }

    #ProjectInstaller.cs

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

    https://candordeveloper.com/2012/12/28/simple-installer-for-windows-service-using-visual-studio-2012/

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已建议为答案 youareok 2018年9月7日 6:41
    2018年9月7日 5:51
    版主