public async ValueTask ProcessAsync(DotNetWatchContext context, CancellationToken cancellationToken) { tempContext = context; if (_suppressLaunchBrowser) { return; } if (context.Iteration == 0) { _reporter = context.Reporter; if (CanLaunchBrowser(context, out var launchPath)) { context.Reporter.Verbose("dotnet-watch is configured to launch a browser on ASP.NET Core application startup."); _canLaunchBrowser = true; _launchPath = launchPath; _cancellationToken = cancellationToken; // We've redirected the output, but want to ensure that it continues to appear in the user's console. context.ProcessSpec.OnOutput += (_, eventArgs) => Console.WriteLine(eventArgs.Data); context.ProcessSpec.OnOutput += OnOutput; if (!_suppressBrowserRefresh) { _refreshServer = new BrowserRefreshServer(context.Reporter); var serverUrl = await _refreshServer.StartAsync(cancellationToken); context.Reporter.Verbose($"Refresh server running at {serverUrl}."); context.ProcessSpec.EnvironmentVariables["ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT"] = serverUrl; var pathToMiddleware = Path.Combine(AppContext.BaseDirectory, "middleware", "Microsoft.AspNetCore.Watch.BrowserRefresh.dll"); context.ProcessSpec.EnvironmentVariables["DOTNET_STARTUP_HOOKS"] = pathToMiddleware; context.ProcessSpec.EnvironmentVariables["ASPNETCORE_HOSTINGSTARTUPASSEMBLIES"] = "Microsoft.AspNetCore.Watch.BrowserRefresh"; } } } if (_canLaunchBrowser) { if (context.Iteration > 0) { // We've detected a change. Notify the browser. await SendMessage(WaitMessage, cancellationToken); } } }
public async ValueTask ProcessAsync(DotNetWatchContext context, CancellationToken cancellationToken) { if (_suppressLaunchBrowser) { return; } if (context.Iteration == 0) { _reporter = context.Reporter; if (CanLaunchBrowser(context, out var launchPath)) { context.Reporter.Verbose("dotnet-watch is configured to launch a browser on ASP.NET Core application startup."); _launchPath = launchPath; _cancellationToken = cancellationToken; // We've redirected the output, but want to ensure that it continues to appear in the user's console. context.ProcessSpec.OnOutput += (_, eventArgs) => Console.WriteLine(eventArgs.Data); context.ProcessSpec.OnOutput += OnOutput; if (!_suppressBrowserRefresh) { _refreshServer = new BrowserRefreshServer(context.Reporter); context.BrowserRefreshServer = _refreshServer; var serverUrls = string.Join(',', await _refreshServer.StartAsync(cancellationToken)); context.Reporter.Verbose($"Refresh server running at {serverUrls}."); context.ProcessSpec.EnvironmentVariables["ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT"] = serverUrls; var pathToMiddleware = Path.Combine(AppContext.BaseDirectory, "middleware", "Microsoft.AspNetCore.Watch.BrowserRefresh.dll"); context.ProcessSpec.EnvironmentVariables.DotNetStartupHooks.Add(pathToMiddleware); context.ProcessSpec.EnvironmentVariables.AspNetCoreHostingStartupAssemblies.Add("Microsoft.AspNetCore.Watch.BrowserRefresh"); } } } else if (!_suppressBrowserRefresh) { // We've detected a change. Notify the browser. await(_refreshServer?.SendWaitMessageAsync(cancellationToken) ?? default); } }
public async ValueTask ProcessAsync(DotNetWatchContext context, CancellationToken cancellationToken) { if (_suppressLaunchBrowser) { return; } if (context.Iteration == 0) { _reporter = context.Reporter; if (CanLaunchBrowser(context, out var launchPath)) { context.Reporter.Verbose("dotnet-watch is configured to launch a browser on ASP.NET Core application startup."); _canLaunchBrowser = true; _launchPath = launchPath; _cancellationToken = cancellationToken; _refreshServer = new BrowserRefreshServer(context.Reporter); var serverUrl = await _refreshServer.StartAsync(cancellationToken); context.Reporter.Verbose($"Refresh server running at {serverUrl}."); context.ProcessSpec.EnvironmentVariables["DOTNET_WATCH_REFRESH_URL"] = serverUrl; context.ProcessSpec.OnOutput += OnOutput; } } if (_canLaunchBrowser) { if (context.Iteration > 0) { // We've detected a change. Notify the browser. await _refreshServer.SendMessage(WaitMessage, cancellationToken); } } }