8

I am new in net core 2.0.

I am connecting to datbase. I am used to use an App.Config or Web.Config to set the connection string. But in net core 2.0 uses appsettings.json file instead.

When I compile de Application, appsettings.json file is not generated in bin directory. So when I run the appplication from Console c>dotnet prj.dll thrown an excepción because connection file is not found.

My question is... I have to copy appsettings.json file manually to bin directory or is there a way to save it in bin directory when Project is compiled?

thanks

Diego
  • 2,238
  • 4
  • 31
  • 68
  • 3
    Have a look at: https://stackoverflow.com/questions/39749344/copying-files-on-compile-for-asp-net-core-1-0-project and https://stackoverflow.com/questions/38178340/how-can-i-ensure-that-appsettings-dev-json-gets-copied-to-the-output-folder – Chris Feb 09 '18 at 15:26

1 Answers1

22

I've been looking for an answer to this question and most of the posts I've found reference the project.json file which has now been deprecated in favour of the .csproj file according to this guide published March 2017.

This document also indicates how you can use the "CopyToOutputDirectory" attribute in your .csproj file to ensure your appsettings.json file is copied to the output directory on build:

<Project ...>
    ...
    <ItemGroup>
        <None Include="appsettings.json" CopyToOutputDirectory="Always" />
    </ItemGroup>
</Project>

.

John Trenwith
  • 753
  • 6
  • 10
  • 1
    Also, if you use Visual Studio and don’t want to edit .csproj file manually you can “Right click” appsettings.json file and choose “Properties”. In “Advanced” find “Copy to Output Directory” and choose “Copy always”. – Tom K Dec 23 '19 at 14:37