public static BrowserLauncher CreateForPlatform() { BrowserLauncher browserLauncher = null; #if NET461 browserLauncher = new BrowserLauncher("CMD.exe", "/C start {0}", false); #else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { browserLauncher = new BrowserLauncher("CMD.exe", "/C start {0}", false); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { browserLauncher = new BrowserLauncher("xdg-open"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { browserLauncher = new BrowserLauncher("open"); } #endif return(browserLauncher); }
public static void Main(string[] args) { var options = new Options(args); if (options.Help) { options.GetHelpTextLines().ForEach(Console.WriteLine); return; } options.OptionErrors.ForEach(Console.Error.WriteLine); var uri = options.PortNumberProvided ? BuildUrl(options.PortNumber) : null; var process = StartDotNetRun(options.UnknownArgs, uri); var actualUri = string.Empty; var reader = process.StandardOutput; while (!reader.EndOfStream) { var line = reader.ReadLine(); actualUri = GetUriFromConsoleLine(line); if (actualUri.Length > 0 && options.ShouldOpenBrowser) { var launchBrowser = BrowserLauncher.CreateForPlatform(); if (launchBrowser == null) { Console.Out.WriteLine("Unable to detect platform, cannot launch browser."); } else { launchBrowser.Launch(actualUri); } } Console.Out.WriteLine(line); } }