Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

CreateDefaultBuilder() does not load and apply appsettings.json #247

Closed
@686d7066

Description

@686d7066

Hello,

we have a dotnet core 2.0 application with an "appsettings.json" in the root of the project.
When starting the application using the code desribed in the "Migrating from ASP.NET Core 1.x to ASP.NET Core 2.0" blog post the settings are not loaded as expected. This is especially visible as the set Url is not used to start the application.

The appsettings.json in question:

{
	"ConnectionStrings, Logging, etc.":  ...
	"Urls": "http://localhost:5005/",
	"Environment": "Development"
}

The code in use:

public class Program
{
	public static void Main(string[] args)
	{
		BuildWebHost(args).Run();
	}

	public static IWebHost BuildWebHost(string[] args) =>
		WebHost.CreateDefaultBuilder(args)    
		.UseStartup<Startup>()
		.Build();
}

For testing we switch back to ye olde way and it works :

public class Program
{
	public static void Main(string[] args)
	{
		var configuration = new ConfigurationBuilder()
			.SetBasePath(Directory.GetCurrentDirectory())
			.AddJsonFile("appSettings.json", optional: true, reloadOnChange: true)
			.Build();

		var host = new WebHostBuilder()
			.UseKestrel()
			.UseConfiguration(configuration)
			.UseContentRoot(Directory.GetCurrentDirectory())
			.UseIISIntegration()
			.UseStartup<Startup>()
			.UseApplicationInsights()
			.Build();

		host.Run();
	}
}

Now the application starts under the expected Url.
It also works if we set the App URL in the properties but we´d prefer to be able to configure everything in one file.

According to the blog post, the CreateDefaultBuilder should load the appsettings.json automatically and apply the configuration.
We´ve looked up the code here on GitHub and it seems as if it should work as expected so maybe we are missing something (obvious) here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions