Paul Duer
Paul Duer

Reputation: 1120

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?

Upvotes: 6

Views: 6827

Answers (1)

chaami
chaami

Reputation: 1494

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.

Upvotes: 4

Related Questions