Reputation: 855
I've setup my active solution configuration to determine the appsettings.json
file to use for the given build. I'm wondering if this is a recommended way the two in combination with each other, or if there an alternative best practice for managing configurations?
I deploy via publishing profiles within Visual Studio as I do not have a CICD pipeline.
There is an underlying assumption that Local
is Debug
and Staging
and Prod
are Release
builds.
The appsettings files are registered as follows:
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true)
.Build();
Launch settings:
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "$(ConfigurationName)"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7184;http://localhost:5081"
},
Project file to prevent configs from being published to unnecessary environments:
<ItemGroup>
<Content Update="appsettings.Local.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Staging.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Prod.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.$(ConfigurationName).json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
My configuration files are:
And finally my configuration manager profiles are:
Upvotes: 0
Views: 77