Visual Studio缺少服务项目中的“添加安装程序”链接
问题描述:
我正在构建Windows服务,并且遵循this MSDN article,但我在“创建安装程序”下的步骤3中被卡住了。我找不到它所指的“添加安装程序”链接。我点击了任何地方,包括按照它给出的指示,但我似乎无法找到它。 Google上的一些人遇到了同样的问题,但从未找到解决方案(除了添加ServiceInstaller对象并手动配置)。Visual Studio缺少服务项目中的“添加安装程序”链接
有没有其他人有这个问题,并找到一个原因?如果它很重要,我使用VS2008并定位.Net 2.0。
答
他们正在讨论的“灰色区域”是“属性”面板属性(不是拼写错误)中的“命令”面板。这不是很有用,所以你可能已经关闭了,我做到了。
您可以通过右键单击属性面板并选择“命令”来重新启用它,或通过右键单击服务设计视图直接添加安装程序项目(带有“向您的组件添加组件”类...“)并选择”添加安装程序“。
答
对于Visual Studio 2012,右键单击“Services1.cs”并选择“视图设计器”(或按Shift-F7)。然后,右键点击设计师的灰色背景。
然后,只有这样,你才能看到微软一直隐藏的复活节彩蛋:难以捉摸的Add Installer
链接。
答
要获得最新的与新的Visual Studio速成(2015)版本:
看来,我们不能有这种从速成版“添加安装程序”。但它确实很简单。你只需要创建一个类并添加下面的代码。
还需要添加引用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);
}
}
}
只是为了记录,这是完全废话,它默认情况下隐藏(或MSDN文档不是更清晰)。你在听,MSFT? – SqlRyan 2009-01-02 20:01:04
@SqlRyan阿门,这让我非常疯狂。 – Contango 2013-09-23 15:26:59