Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio doesn't publish appsettings.json file for DotNet Core Console App

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?

like image 863
Paul Duer Avatar asked Apr 21 '17 12:04

Paul Duer


People also ask

How do I add Appsettings json file to .NET Core console app?

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.

How do I add Appsettings production json in Visual Studio?

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.


Video Answer


1 Answers

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.

like image 186
chaami Avatar answered Jan 03 '23 15:01

chaami