When you start an ASP.NET Core project from Visual Studio (2017) it assumes the working directory is where the source code is located, not where the built files are actually placed.
Which means that when I run my project it reads the config file from C:\Path\To\My\Project\appsettings.json, and not from C:\Path\To\My\Project\bin\Debug\appsettings.json.
I can see that this is the case when I debug this code:
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((context, config) => {
config.SetBasePath(context.HostingEnvironment.ContentRootPath);
config.AddJsonFile("appsettings.json", true, false);
});
Where ContentRootPath points to the project folder, not where the built files are placed.
I could probably fix this by setting the Working Directory in Project Properties > Debug, but seeing as we're also using configuration transforms (SlowCheetah), each developer will have their own build configuration for debug output (bin\Debug[CustomConfiguration]), and changing .csproj for one developer breaks it for all the other developers.
Is there any way of having ASP.NET Core read the config files from where the built files are placed instead of the project folder, without having to change the Working Directory, yet still working for multiple "Build Configurations"?
Maybe this will help is set to directory as application working directory by: