Do not overwrite ContentRoot #267

This commit is contained in:
Chris Ross (ASP.NET) 2018-05-24 11:18:31 -07:00
parent 30b506a02d
commit 48a9013e08
4 changed files with 20 additions and 14 deletions

View File

@ -149,12 +149,21 @@ namespace Microsoft.AspNetCore
/// <returns>The initialized <see cref="IWebHostBuilder"/>.</returns> /// <returns>The initialized <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder CreateDefaultBuilder(string[] args) public static IWebHostBuilder CreateDefaultBuilder(string[] args)
{ {
var builder = new WebHostBuilder() var builder = new WebHostBuilder();
.UseKestrel((builderContext, options) =>
if (string.IsNullOrEmpty(builder.GetSetting(WebHostDefaults.ContentRootKey)))
{
builder.UseContentRoot(Directory.GetCurrentDirectory());
}
if (args != null)
{
builder.UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build());
}
builder.UseKestrel((builderContext, options) =>
{ {
options.Configure(builderContext.Configuration.GetSection("Kestrel")); options.Configure(builderContext.Configuration.GetSection("Kestrel"));
}) })
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) => .ConfigureAppConfiguration((hostingContext, config) =>
{ {
var env = hostingContext.HostingEnvironment; var env = hostingContext.HostingEnvironment;
@ -209,11 +218,6 @@ namespace Microsoft.AspNetCore
options.ValidateScopes = context.HostingEnvironment.IsDevelopment(); options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
}); });
if (args != null)
{
builder.UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build());
}
return builder; return builder;
} }

View File

@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Tests
var applicationName = "CreateDefaultBuilderApp"; var applicationName = "CreateDefaultBuilderApp";
await ExecuteTestApp(applicationName, async (deploymentResult, logger) => await ExecuteTestApp(applicationName, async (deploymentResult, logger) =>
{ {
var response = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync(string.Empty), logger, deploymentResult.HostShutdownToken); var response = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync(string.Empty), logger, deploymentResult.HostShutdownToken, retryCount: 5);
var responseText = await response.Content.ReadAsStringAsync(); var responseText = await response.Content.ReadAsStringAsync();
try try
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Tests
var applicationName = "CreateDefaultBuilderOfTApp"; var applicationName = "CreateDefaultBuilderOfTApp";
await ExecuteTestApp(applicationName, async (deploymentResult, logger) => await ExecuteTestApp(applicationName, async (deploymentResult, logger) =>
{ {
var response = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync(string.Empty), logger, deploymentResult.HostShutdownToken); var response = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync(string.Empty), logger, deploymentResult.HostShutdownToken, retryCount: 5);
var responseText = await response.Content.ReadAsStringAsync(); var responseText = await response.Content.ReadAsStringAsync();
try try

View File

@ -35,9 +35,10 @@ namespace CreateDefaultBuilderApp
private static string GetResponseMessage(WebHostBuilderContext context, IServiceCollection services) private static string GetResponseMessage(WebHostBuilderContext context, IServiceCollection services)
{ {
// Verify ContentRootPath set // Verify ContentRootPath set
if (!string.Equals(Directory.GetCurrentDirectory(), context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal)) var contentRoot = Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT");
if (!string.Equals(contentRoot, context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal))
{ {
return $"Current directory incorrect. Expected: {Directory.GetCurrentDirectory()} Actual: {context.HostingEnvironment.ContentRootPath}"; return $"ContentRootPath incorrect. Expected: {contentRoot} Actual: {context.HostingEnvironment.ContentRootPath}";
} }
// Verify appsettings.json loaded // Verify appsettings.json loaded

View File

@ -26,9 +26,10 @@ namespace CreateDefaultBuilderOfTApp
private static string GetResponseMessage(WebHostBuilderContext context, IOptions<HostFilteringOptions> hostFilteringOptions) private static string GetResponseMessage(WebHostBuilderContext context, IOptions<HostFilteringOptions> hostFilteringOptions)
{ {
// Verify ContentRootPath set // Verify ContentRootPath set
if (!string.Equals(Directory.GetCurrentDirectory(), context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal)) var contentRoot = Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT");
if (!string.Equals(contentRoot, context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal))
{ {
return $"Current directory incorrect. Expected: {Directory.GetCurrentDirectory()} Actual: {context.HostingEnvironment.ContentRootPath}"; return $"ContentRootPath incorrect. Expected: {contentRoot} Actual: {context.HostingEnvironment.ContentRootPath}";
} }
// Verify appsettings.json loaded // Verify appsettings.json loaded