6

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?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Paul Duer
  • 1,100
  • 1
  • 13
  • 32
  • 1
    `appsettings.json` is an json file and nothing more. So it's OK to setup `Build action` and `Copy to output directory` actions manually. – Ilya Chumakov Apr 21 '17 at 13:12
  • Seems like default action for any JSON file added is "Do not copy" regardless the name ... – Ignas Apr 21 '17 at 14:36
  • 1
    The `.csproj` should have the following: `PreserveNewest` – Boggin Apr 21 '17 at 16:13
  • 2
    I wonder how others deal with this? I mean don't others write console apps and don't they need settings? I always wonder about everybody else's life that develop everyday. – Paul Duer Apr 21 '17 at 16:59
  • Well, some if not most settings are going to be environment-specific, and as such should not be deployed with the app. In many cases, the place where config is stored is completely different (it's common to have a json file in dev, and env variables in prod). – Bertrand Le Roy Apr 21 '17 at 17:17
  • Yeah that makes sense! We're not that fancy I guess! :) – Paul Duer Apr 21 '17 at 19:56

1 Answers1

3

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.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
chaami
  • 1,306
  • 1
  • 9
  • 10