Visual Studio missing “Add Installer” link in service project

允我心安 提交于 2019-12-01 17:27:19

问题


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.


回答1:


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".




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/407459/visual-studio-missing-add-installer-link-in-service-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!