public AspNetProcess( ITestOutputHelper output, string workingDirectory, string dllPath, IDictionary <string, string> environmentVariables, bool published, bool hasListeningUri = true, ILogger logger = null) { _developmentCertificate = DevelopmentCertificate.Create(workingDirectory); _output = output; _httpClient = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = true, UseCookies = true, CookieContainer = new CookieContainer(), ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => (certificate.Subject != "CN=localhost" && errors == SslPolicyErrors.None) || certificate?.Thumbprint == _developmentCertificate.CertificateThumbprint, }) { Timeout = TimeSpan.FromMinutes(2) }; output.WriteLine("Running ASP.NET Core application..."); var arguments = published ? $"exec {dllPath}" : "run --no-build"; logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}"); var finalEnvironmentVariables = new Dictionary <string, string>(environmentVariables) { ["ASPNETCORE_Kestrel__Certificates__Default__Path"] = _developmentCertificate.CertificatePath, ["ASPNETCORE_Kestrel__Certificates__Default__Password"] = _developmentCertificate.CertificatePassword, }; Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments, envVars: finalEnvironmentVariables); logger?.LogInformation("AspNetProcess - process started"); if (hasListeningUri) { logger?.LogInformation("AspNetProcess - Getting listening uri"); ListeningUri = ResolveListeningUrl(output); logger?.LogInformation($"AspNetProcess - Got {ListeningUri}"); } }
public AspNetProcess( ITestOutputHelper output, string workingDirectory, string dllPath, IDictionary <string, string> environmentVariables, bool published, bool hasListeningUri = true, bool usePublishedAppHost = false, ILogger logger = null) { _developmentCertificate = DevelopmentCertificate.Create(workingDirectory); _output = output; _httpClient = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = true, UseCookies = true, CookieContainer = new CookieContainer(), ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => (certificate.Subject != "CN=localhost" && errors == SslPolicyErrors.None) || certificate?.Thumbprint == _developmentCertificate.CertificateThumbprint, }) { Timeout = TimeSpan.FromMinutes(2) }; output.WriteLine("Running ASP.NET Core application..."); string process; string arguments; if (published) { if (usePublishedAppHost) { // When publishingu used the app host to run the app. This makes it easy to consistently run for regular and single-file publish process = Path.ChangeExtension(dllPath, OperatingSystem.IsWindows() ? ".exe" : null); arguments = null; } else { process = DotNetMuxer.MuxerPathOrDefault(); arguments = $"exec {dllPath}"; } } else { process = DotNetMuxer.MuxerPathOrDefault(); arguments = "run --no-build"; } logger?.LogInformation($"AspNetProcess - process: {process} arguments: {arguments}"); var finalEnvironmentVariables = new Dictionary <string, string>(environmentVariables) { ["ASPNETCORE_Kestrel__Certificates__Default__Path"] = _developmentCertificate.CertificatePath, ["ASPNETCORE_Kestrel__Certificates__Default__Password"] = _developmentCertificate.CertificatePassword, }; Process = ProcessEx.Run(output, workingDirectory, process, arguments, envVars: finalEnvironmentVariables); logger?.LogInformation("AspNetProcess - process started"); if (hasListeningUri) { logger?.LogInformation("AspNetProcess - Getting listening uri"); ListeningUri = ResolveListeningUrl(output); logger?.LogInformation($"AspNetProcess - Got {ListeningUri}"); } }