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

发布于 2024-07-10 21:03:57 字数 356 浏览 5 评论 0原文

I'm building a Windows service and following this MSDN article, but I'm stuck on step 3 under "Create an installer". I can't find the "Add Installer" link it's referring to. I've clicked everywhere, including following the instructions it gives exactly, but I can't seem to find it. A few people on Google have had the same problem, but never found a solution (other than adding the ServiceInstaller object and configuring it manually).

Has anybody else had this problem and found a reason? I'm using VS2008 and targeting .Net 2.0 if it matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

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

然后,也只有到那时,您才会看到微软一直向您隐藏的复活节彩蛋:难以捉摸的添加安装程序链接。

在此处输入链接描述

For Visual Studio 2012, right click on "Services1.cs" and select "View Designer" (or press Shift-F7). Then, right click on the grey background of the designer.

Then, and only then, will you see the Easter Egg that Microsoft has been hiding from you all this time: the elusive Add Installer link.

enter link description here

雅心素梦 2024-07-17 21:03:58

检查您尝试添加安装程序的 .cs 文件是否扩展了 System.ServiceProcess.ServiceBase 而不是 System.ComponentModel.Component

要将 .cs 文件作为代码而不是在设计器中打开,请在解决方案资源管理器中选择它并按 F7 或右键单击它并选择“查看代码”。

Check that the .cs file where you're trying to add the installer extends System.ServiceProcess.ServiceBase and not System.ComponentModel.Component.

To open the .cs file as code and not in the designer, select it in the Solution Explorer and press F7 or right click it and select "View Code".

暮年 2024-07-17 21:03:57

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

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

The "Gray area" they're talking about is the Commands panel from Properties of the Properties panel (not a typo). It is not very useful so you have probably shut it off, I did.

You can either re-enable it by right-clicking the Properties panel and selecting "Commands", or add an Installer project directly by right-clicking the Service design view (the big tan window with "To add components to your class...") and selecting "Add Installer".

软的没边 2024-07-17 21:03:57

要更新新的 Visual Studio Express(2015) 版本:

看来我们无法从 Express 版本中获得此“添加安装程序”。 但这确实很简单。 您只需创建一个类并添加以下代码即可。

您还需要添加引用 System.Configuration.Install.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);
        }
    }
}

To get up to date with the new visual studio express(2015) version:

It seems that we cannot have this "Add Installer" from the express edition. But it's quite simple really. You simply need to create a class and add the below code.

Also you need to add the reference System.Configuration.Install.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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文