private async Task <Uri> RunKestrel() { await package.EnsurePublished(); var operation = Log.OnEnterAndExit(); var process = CommandLine.StartProcess( Dotnet.Path.FullName, package.EntryPointAssemblyPath.FullName, package.Directory, StandardOutput.OnNext, StandardError.OnNext, ("ASPNETCORE_DETAILEDERRORS", "1"), ("ASPNETCORE_URLS", $"http://127.0.0.1:0"), ("ASPNETCORE_PORT", null)); _disposables.Add(() => { operation.Dispose(); process.Kill(); }); _disposables.Add(StandardOutput.Subscribe(s => operation.Trace(s))); _disposables.Add(StandardError.Subscribe(s => operation.Error(s))); var kestrelListeningMessagePrefix = "Now listening on:"; var uriString = await StandardOutput .Where(line => line.Contains(kestrelListeningMessagePrefix)) .Select(line => line.Replace(kestrelListeningMessagePrefix, "")) .FirstAsync(); operation.Trace("Starting Kestrel at {uri}.", uriString); return(new Uri(uriString)); }