I'm building a DotNet Core console application. I have noticed that when I publish the application to the file system, the appsettings.json file is NOT included in the output files.
I've found that changing the copy option on the appsettings can make it appear, but it doesn't by default.
Shouldn't appsettings be included as a separate file in a console application so that you can configure the app on the fly?
Add Json File After adding the file, right click on appsettings. json and select properties. Then set “Copy to Ouptut Directory” option to Copy Always. Add few settings to json file, so that you can verify that those settings are loaded.
First, in Visual Studio you will have to right click your project name and add a new item. Inside 'Add new Item' window chose 'Scripts' on the left column, and look for JavaScript JSON Configuration File template. Name it as appsettings. Production.
I think the file is left behind by default for security reasons (password in a connectionString ?).
You can use the this answer to get your files copied.
By default the appsettings.json is part of the default <ItemGroup>
of the project, so add the <None>
tag for the copy inside the one listing the <PackageReference>
nodes.
<None Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
You can use this link for more information about safe storage of app secrets in .Net Core.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With