A common nuisance we have is having to switch this code below depending on whether we are testing locally or committing code for the build server.
/// <summary>
/// Main entry point to the application.
/// </summary>
public static void Main()
{
// Don't forget to uncomment this if committing (!)
//var servicesToRun = new ServiceBase[] {new myservice()};
//ServiceBase.Run(servicesToRun);
// and re-comment this
RunAsConsoleApp();
}
It would be really useful if there was a way to test in the code to tell the output type i.e, and avoid all the 'oh-no I committed and broke the build' time wasting.
if (IsConsoleApp)
{
Using(var host= new ServiceHost(typeof(myservice))
{
host.Open();
etc....
}
}
else
{
var servicesToRun = new ServiceBase[] {new myservice()};
ServiceBase.Run(servicesToRun);
}