Add environment variables to dotnet publish
This commit is contained in:
parent
0a7cf6b5a0
commit
d2f109ef6c
|
|
@ -91,7 +91,12 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
/// Environment variables to be set before starting the host.
|
/// Environment variables to be set before starting the host.
|
||||||
/// Not applicable for IIS Scenarios.
|
/// Not applicable for IIS Scenarios.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<KeyValuePair<string, string>> EnvironmentVariables { get; private set; } = new List<KeyValuePair<string, string>>();
|
public List<KeyValuePair<string, string>> EnvironmentVariables { get; } = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Environment variables used when invoking dotnet publish.
|
||||||
|
/// </summary>
|
||||||
|
public List<KeyValuePair<string, string>> PublishEnvironmentVariables { get; } = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For any application level cleanup to be invoked after performing host cleanup.
|
/// For any application level cleanup to be invoked after performing host cleanup.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
@ -64,6 +65,8 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
RedirectStandardOutput = true
|
RedirectStandardOutput = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.PublishEnvironmentVariables);
|
||||||
|
|
||||||
var hostProcess = new Process() { StartInfo = startInfo };
|
var hostProcess = new Process() { StartInfo = startInfo };
|
||||||
hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogWarning(dataArgs.Data ?? string.Empty); };
|
hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogWarning(dataArgs.Data ?? string.Empty); };
|
||||||
hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogTrace(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<KeyValuePair<string, string>> environmentVariables)
|
||||||
{
|
{
|
||||||
var environment =
|
var environment =
|
||||||
#if NET451
|
#if NET451
|
||||||
|
|
@ -134,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
|
|
||||||
SetEnvironmentVariable(environment, "ASPNETCORE_ENVIRONMENT", DeploymentParameters.EnvironmentName);
|
SetEnvironmentVariable(environment, "ASPNETCORE_ENVIRONMENT", DeploymentParameters.EnvironmentName);
|
||||||
|
|
||||||
foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables)
|
foreach (var environmentVariable in environmentVariables)
|
||||||
{
|
{
|
||||||
SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value);
|
SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
RedirectStandardOutput = true
|
RedirectStandardOutput = true
|
||||||
};
|
};
|
||||||
|
|
||||||
AddEnvironmentVariablesToProcess(startInfo);
|
AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables);
|
||||||
|
|
||||||
_hostProcess = new Process() { StartInfo = startInfo };
|
_hostProcess = new Process() { StartInfo = startInfo };
|
||||||
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); };
|
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); };
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
WorkingDirectory = workingDirectory
|
WorkingDirectory = workingDirectory
|
||||||
};
|
};
|
||||||
|
|
||||||
AddEnvironmentVariablesToProcess(startInfo);
|
AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables);
|
||||||
|
|
||||||
_hostProcess = new Process() { StartInfo = startInfo };
|
_hostProcess = new Process() { StartInfo = startInfo };
|
||||||
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); };
|
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue