public static void Main(string[] args) { if (Environment.CommandLine.Contains("LiveReloadWebServer", StringComparison.InvariantCultureIgnoreCase)) { Helpers.ExeName = "LiveReloadWebServer"; } try { var version = Assembly.GetExecutingAssembly().GetName().Version; var ver = version.Major + "." + version.Minor + (version.Build > 0 ? "." + version.Build : string.Empty); Helpers.AppHeader = $"Live Reload Web Server v{ver}"; if (args.Contains("--help", StringComparer.InvariantCultureIgnoreCase) || args.Contains("/h") || args.Contains("-h")) { ShowHelp(); return; } var builder = CreateHostBuilder(args); if (builder == null) { return; } WebHost = builder.Build(); WebHost.Run(); } catch (IOException ex) { ColorConsole.WriteWarning("\r\nUnable to start the Web Server."); Console.WriteLine("------------------------------"); ColorConsole.WriteWrappedHeader("\r\nUnable to start the Web Server.", headerColor: ConsoleColor.DarkYellow); Console.WriteLine("Most likely the server port is already in use by another application."); Console.WriteLine("Please try and choose another port with the `--port` switch. And try again."); Console.WriteLine("\r\n\r\n"); ColorConsole.WriteError(ex.Message); Console.WriteLine("---------------------------------------------------------------------------"); } catch (SocketException ex) { ColorConsole.WriteError("\r\nUnable to start the Web Server."); Console.WriteLine("------------------------------"); Console.WriteLine("The server Host IP address is invalid."); Console.WriteLine("Please try and choose another host IP address with the `--host` switch. And try again."); Console.WriteLine("\r\n\r\n"); ColorConsole.WriteError(ex.Message); Console.WriteLine("---------------------------------------------------------------------------"); } catch (Exception ex) { // can't catch internal type if (ex.StackTrace.Contains("ThrowOperationCanceledException")) { return; } WriteStartupErrorMessage(ex.Message, ex.StackTrace, ex.Source); } }