[ANCM] Add switch to prefer env over web.config (#19746)
This commit is contained in:
parent
56a64a6ff0
commit
fdaa334567
|
|
@ -13,6 +13,7 @@
|
||||||
#define ASPNETCORE_IIS_AUTH_BASIC L"basic;"
|
#define ASPNETCORE_IIS_AUTH_BASIC L"basic;"
|
||||||
#define ASPNETCORE_IIS_AUTH_ANONYMOUS L"anonymous;"
|
#define ASPNETCORE_IIS_AUTH_ANONYMOUS L"anonymous;"
|
||||||
#define ASPNETCORE_IIS_AUTH_NONE L"none"
|
#define ASPNETCORE_IIS_AUTH_NONE L"none"
|
||||||
|
#define ANCM_PREFER_ENVIRONMENT_VARIABLES_ENV_STR L"ANCM_PREFER_ENVIRONMENT_VARIABLES"
|
||||||
|
|
||||||
//
|
//
|
||||||
// The key used for hash-table lookups, consists of the port on which the http process is created.
|
// The key used for hash-table lookups, consists of the port on which the http process is created.
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,27 @@ public:
|
||||||
environmentVariables.insert_or_assign(HOSTING_STARTUP_ASSEMBLIES_ENV_STR, hostingStartupValues);
|
environmentVariables.insert_or_assign(HOSTING_STARTUP_ASSEMBLIES_ENV_STR, hostingStartupValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto preferEnvironmentVariablesSetting = Environment::GetEnvironmentVariableValue(ANCM_PREFER_ENVIRONMENT_VARIABLES_ENV_STR).value_or(L"false");
|
||||||
|
auto preferEnvironmentVariables = equals_ignore_case(L"1", preferEnvironmentVariablesSetting) || equals_ignore_case(L"true", preferEnvironmentVariablesSetting);
|
||||||
|
|
||||||
for (auto& environmentVariable : environmentVariables)
|
for (auto& environmentVariable : environmentVariables)
|
||||||
{
|
{
|
||||||
environmentVariable.second = Environment::ExpandEnvironmentVariables(environmentVariable.second);
|
if (preferEnvironmentVariables)
|
||||||
|
{
|
||||||
|
auto env = Environment::GetEnvironmentVariableValue(environmentVariable.first);
|
||||||
|
if (env.has_value())
|
||||||
|
{
|
||||||
|
environmentVariable.second = env.value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
environmentVariable.second = Environment::ExpandEnvironmentVariables(environmentVariable.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
environmentVariable.second = Environment::ExpandEnvironmentVariables(environmentVariable.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return environmentVariables;
|
return environmentVariables;
|
||||||
|
|
|
||||||
|
|
@ -126,5 +126,22 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.InProcess
|
||||||
deploymentParameters.WebConfigBasedEnvironmentVariables["OtherVariable"] = "%TestVariable%;Hello";
|
deploymentParameters.WebConfigBasedEnvironmentVariables["OtherVariable"] = "%TestVariable%;Hello";
|
||||||
Assert.Equal("World;Hello", await GetStringAsync(deploymentParameters, "/GetEnvironmentVariable?name=OtherVariable"));
|
Assert.Equal("World;Hello", await GetStringAsync(deploymentParameters, "/GetEnvironmentVariable?name=OtherVariable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ConditionalTheory]
|
||||||
|
[RequiresIIS(IISCapability.PoolEnvironmentVariables)]
|
||||||
|
[RequiresNewHandler]
|
||||||
|
[RequiresNewShim]
|
||||||
|
[InlineData(HostingModel.InProcess)]
|
||||||
|
[InlineData(HostingModel.OutOfProcess)]
|
||||||
|
public async Task PreferEnvironmentVariablesOverWebConfigWhenConfigured(HostingModel hostingModel)
|
||||||
|
{
|
||||||
|
var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel);
|
||||||
|
|
||||||
|
var environment = "Development";
|
||||||
|
deploymentParameters.EnvironmentVariables["ANCM_PREFER_ENVIRONMENT_VARIABLES"] = "true";
|
||||||
|
deploymentParameters.EnvironmentVariables["ASPNETCORE_ENVIRONMENT"] = environment;
|
||||||
|
deploymentParameters.WebConfigBasedEnvironmentVariables.Add("ASPNETCORE_ENVIRONMENT", "Debug");
|
||||||
|
Assert.Equal(environment, await GetStringAsync(deploymentParameters, "/GetEnvironmentVariable?name=ASPNETCORE_ENVIRONMENT"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,11 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
|
||||||
|
|
||||||
var ancmConfigPath = Path.Combine(Environment.SystemDirectory, "inetsrv", "config", "schema", "aspnetcore_schema.xml");
|
var ancmConfigPath = Path.Combine(Environment.SystemDirectory, "inetsrv", "config", "schema", "aspnetcore_schema.xml");
|
||||||
|
|
||||||
|
if (!File.Exists(ancmConfigPath))
|
||||||
|
{
|
||||||
|
ancmConfigPath = Path.Combine(Environment.SystemDirectory, "inetsrv", "config", "schema", "aspnetcore_schema_v2.xml");
|
||||||
|
}
|
||||||
|
|
||||||
if (!File.Exists(ancmConfigPath) && !SkipInVSTSAttribute.RunningInVSTS)
|
if (!File.Exists(ancmConfigPath) && !SkipInVSTSAttribute.RunningInVSTS)
|
||||||
{
|
{
|
||||||
_skipReasonStatic = "IIS Schema is not installed.";
|
_skipReasonStatic = "IIS Schema is not installed.";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue