diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs index 4aa0e64f5d..9b2187c8b1 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs @@ -91,7 +91,12 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting /// Environment variables to be set before starting the host. /// Not applicable for IIS Scenarios. /// - public List> EnvironmentVariables { get; private set; } = new List>(); + public List> EnvironmentVariables { get; } = new List>(); + + /// + /// Environment variables used when invoking dotnet publish. + /// + public List> PublishEnvironmentVariables { get; } = new List>(); /// /// For any application level cleanup to be invoked after performing host cleanup. diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs index bcefabf7a1..d9fa3e9e8a 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; @@ -64,6 +65,8 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting RedirectStandardOutput = true }; + AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.PublishEnvironmentVariables); + var hostProcess = new Process() { StartInfo = startInfo }; hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogWarning(dataArgs.Data ?? string.Empty); }; hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogTrace(dataArgs.Data ?? string.Empty); }; @@ -123,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting } } - protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo) + protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo, List> environmentVariables) { var environment = #if NET451 @@ -134,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting SetEnvironmentVariable(environment, "ASPNETCORE_ENVIRONMENT", DeploymentParameters.EnvironmentName); - foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables) + foreach (var environmentVariable in environmentVariables) { SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value); } diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs index d7849f009e..9bd70e4d21 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting RedirectStandardOutput = true }; - AddEnvironmentVariablesToProcess(startInfo); + AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables); _hostProcess = new Process() { StartInfo = startInfo }; _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs index d1cf21dd1f..1807be56f3 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting WorkingDirectory = workingDirectory }; - AddEnvironmentVariablesToProcess(startInfo); + AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables); _hostProcess = new Process() { StartInfo = startInfo }; _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); };