You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this blogpost you're talking about sharing appsettings accross multiple projects.
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
var sharedFolder = Path.Combine(env.ContentRootPath, "..", "Shared");
config
.AddJsonFile(Path.Combine(sharedFolder, "SharedSettings.json"), optional: true) // When running using dotnet run
.AddJsonFile("SharedSettings.json", optional: true) // When app is published
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
config.AddEnvironmentVariables();
})
The behavior I observe when setting the Build action and Copy to Output directory properties of my SharedSettings.json file to Content and Copy if newer, respectively, is that dotnet run copies the SharedSettings.json to the build directory as expected. Therefore, it is not needed to specify a path (as seen below) to the relative location of SharedSettings.json.
.AddJsonFile(Path.Combine(sharedFolder, "SharedSettings.json"), optional: true) // When running using dotnet run
This will work for local development, as well post publish. Is this correct? Or am I missing something?
Thanks!
The text was updated successfully, but these errors were encountered:
I understand now. The above is true for Console apps, but not for Web apps where the ContentRoot is not equal to the build directory. I fixed it with this:
Yeah, you got it 🙂 if that works for you, great! I wasn't able to use it that approach, as people run environments locally in multiple ways, so can't make those assumptions based on environment🙂
Hi Andrew,
In this blogpost you're talking about sharing appsettings accross multiple projects.
The behavior I observe when setting the
Build action
andCopy to Output directory
properties of my SharedSettings.json file toContent
andCopy if newer
, respectively, is thatdotnet run
copies the SharedSettings.json to the build directory as expected. Therefore, it is not needed to specify a path (as seen below) to the relative location of SharedSettings.json.This will work for local development, as well post publish. Is this correct? Or am I missing something?
Thanks!
The text was updated successfully, but these errors were encountered: