Ejemplo n.º 1
0
        private (ProcessEx, string url) RunPublishedStandaloneBlazorProject(Project project)
        {
            var publishDir = Path.Combine(project.TemplatePublishDir, "wwwroot");

            Output.WriteLine("Running dotnet serve on published output...");
            var developmentCertificate = DevelopmentCertificate.Create(project.TemplateOutputDir);
            var serveProcess           = ProcessEx.Run(Output, publishDir, DotNetMuxer.MuxerPathOrDefault(), $"serve -S --pfx \"{developmentCertificate.CertificatePath}\" --pfx-pwd \"{developmentCertificate.CertificatePassword}\" --port 0");
            var listeningUri           = ResolveListeningUrl(serveProcess);

            return(serveProcess, listeningUri);
        }
Ejemplo n.º 2
0
        private (ProcessEx, string url) RunPublishedStandaloneBlazorProject(Project project)
        {
            var publishDir = Path.Combine(project.TemplatePublishDir, "wwwroot");

            Output.WriteLine("Running dotnet serve on published output...");
            var developmentCertificate = DevelopmentCertificate.Create(project.TemplateOutputDir);
            var args = $"-S --pfx \"{developmentCertificate.CertificatePath}\" --pfx-pwd \"{developmentCertificate.CertificatePassword}\" --port 0";
            var command = DotNetMuxer.MuxerPathOrDefault();
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX_DIR")))
            {
                args = $"serve " + args;
            }
            else
            {
                command = "dotnet-serve";
                args = "--roll-forward LatestMajor " + args; // dotnet-serve targets net5.0 by default
            }

            var serveProcess = ProcessEx.Run(TestOutputHelper, publishDir, command, args);
            var listeningUri = ResolveListeningUrl(serveProcess);
            return (serveProcess, listeningUri);
        }
Ejemplo n.º 3
0
    public AspNetProcess(
        DevelopmentCertificate cert,
        ITestOutputHelper output,
        string workingDirectory,
        string dllPath,
        IDictionary <string, string> environmentVariables,
        bool published,
        bool hasListeningUri     = true,
        bool usePublishedAppHost = false,
        ILogger logger           = null)
    {
        _developmentCertificate = cert;
        _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();

            // When executing "dotnet run", the launch urls specified in the app's launchSettings.json have higher precedence
            // than ambient environment variables. We specify the urls using command line arguments instead to allow us
            // to continue binding to "port 0" and avoid test flakiness due to port conflicts.
            arguments = $"run --no-build --urls \"{environmentVariables["ASPNETCORE_URLS"]}\"";
        }

        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}");
        }
    }