代码之家  ›  专栏  ›  技术社区  ›  SqlRyan

Visual Studio在服务项目中缺少“添加安装程序”链接

  •  6
  • SqlRyan  · 技术社区  · 16 年前

    我正在构建一个Windows服务并跟踪 this MSDN article ,但我被困在“创建安装程序”下的第3步。我找不到它所指的“添加安装程序”链接。我点击了所有地方,包括完全按照它给出的说明进行操作,但似乎找不到。谷歌上的一些人也遇到了同样的问题,但从未找到解决方案(除了添加ServiceInstaller对象并手动配置它)。

    还有其他人遇到过这个问题并找到了原因吗?我使用VS2008和目标。Net 2.0,如果重要的话。

    4 回复  |  直到 16 年前
        1
  •  6
  •   Dour High Arch    16 年前

    他们谈论的“灰色区域”是“属性”面板的“属性”中的“命令”面板(不是拼写错误)。它不是很有用,所以你可能把它关掉了,我关掉了。

    您可以通过右键单击“属性”面板并选择“命令”来重新启用它,也可以直接右键单击服务设计视图(带有“向类中添加组件…”的大棕褐色窗口)并选择“添加安装程序”来添加安装程序项目。

        2
  •  3
  •   Contango    12 年前

    要了解最新的visual studio express(2015)版本:

    似乎我们无法从快速版本中获得此“添加安装程序”。但其实很简单。您只需创建一个类并添加以下代码。

    您还需要添加参考系统。配置。安装.dll。

    using System.Configuration.Install;
    using System.ServiceProcess;
    using System.ComponentModel;
    
    
    namespace SAS
    {
        [RunInstaller(true)]
        public class MyProjectInstaller : Installer
        {
            private ServiceInstaller serviceInstaller1;
            private ServiceProcessInstaller processInstaller;
    
            public MyProjectInstaller()
            {
                // Instantiate installer for process and service.
                processInstaller = new ServiceProcessInstaller();
                serviceInstaller1 = new ServiceInstaller();
    
                // The service runs under the system account.
                processInstaller.Account = ServiceAccount.LocalSystem;
    
                // The service is started manually.
                serviceInstaller1.StartType = ServiceStartMode.Manual;
    
                // ServiceName must equal those on ServiceBase derived classes.
                serviceInstaller1.ServiceName = "SAS Service";
    
                // Add installer to collection. Order is not important if more than one service.
                Installers.Add(serviceInstaller1);
                Installers.Add(processInstaller);
            }
        }
    }
    
        3
  •  2
  •   Carol    9 年前

    对于Visual Studio 2012,右键单击“Services1.cs”并选择“视图设计器”(或按Shift-F7)。然后,右键单击设计器的灰色背景。

    然后,也只有到那时,你才会看到微软一直瞒着你的复活节彩蛋:难以捉摸的 Add Installer 链接。

    enter link description here

    推荐文章