Anyone with a solution?
There're two open bounties on stackoverflow for this answer:
How to publish environment specific appsettings in .Net core app?
http://stackoverflow.com/questions/39256057/how-to-publish-environment-specific-appsettings-in-net-core-app
How can I ensure that appsettings.{environment}.json gets copied to the output folder?
http://stackoverflow.com/questions/38178340/how-can-i-ensure-that-appsettings-dev-json-gets-copied-to-the-output-folder
That's sounds simple! Until that gets automated it would required us to copy that manually, or we would need to create our own custom script
Yeah, we need a way to tell to "dotnet publish" which publish profile (environment) we are publishing. Something like dotnet publish --environment Staging. Also having two configs (appsettings.json & appsettings.Staging.json) in publish folder is a bad idea... It should be merged during publish, like it was with config transform in classic Asp.Net
This issue is being closed because it has not been updated in 3 months.
We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.
If someone else is wondering how to use different appsettings for multiple environments here is a possible solution.
dotnet publish --configuration [Debug|Release] will copy the appropriate appsettings.json file into the publish folder if *.csproj has a conditional logic for these files:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
<Choose>
<When Condition="'$(Configuration)' == 'Debug'">
<ItemGroup>
<None Include="appsettings.json" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
<None Include="appsettings.prod.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" />
</ItemGroup>
</When>
<When Condition="'$(Configuration)' == 'Release'">
<ItemGroup>
<None Include="appsettings.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" />
<None Include="appsettings.prod.json" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
</ItemGroup>
</When>
</Choose>
Startup.cs try to load both filespublic Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.prod.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
I hope this solution, has been helpful.
When EnableDefaultContentItems is false, this will cause *.cshtml files and other files in wwwroot not able to read and lead to InvalidOperation exception.
Another solution is