当我使用VS2010 SP1时,我编写了一个windows服务。现在我想调试它而不安装它。所以我写的代码如下Program.cs的主要方法:使用预处理器指令在Visual Studio中调试WindowsService #if
#if (DEBUG)
ControllerNTService service =new ControllerNTService();
Console.ReadLine();
#else
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new ControllerNTService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
#endif
我预计在2010年VS不过VS调试Windows服务,代码行下面显示灰色。这意味着灰色代码无效,对吗? (两条线是灰色的)
ControllerNTService service =new ControllerNTService(); Console.ReadLine();
如果代码是有效的,我想我能碰上他们。
另一个问题,使用上面的代码,当我按F5调试它,它表明它不能调试它,我需要先安装服务。
我希望有人遇到类似的问题来指导我。 祝您有美好的一天
非常感谢您的回复。其实,我把我的项目定义为“调试”模式。现在,我遇到了两个问题。第一个是VS禁止我调试。当我按F5进行调试时,VS显示一个对话框“无法从命令行或调试器启动服务”。必须首先安装Windows服务(使用installutil.exe)......“。第二个是我在#if #else中的代码显示为灰色。这意味着代码无效。 – 2012-04-25 08:51:13