4

I am having a console application, which is using appsettings.json for holding the configuration values.

In Visual Studio IDE , when I set AlwaysCopy for appsettings.json, it will be copied to the DEBUG folder, as part of BUILD.

But, in .net core, when I run dotnet build, it is not copying appsettings.json to DEBUG folder. I am already having below xml configuration added to .csproj

  <Content Include="appsettings.json">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  </Content>

When I do dotnet publish, it is getting copied to publish folder. But, it is not happening when I do dotnet build. Can you please tell, why it is not happening & what should I do to copy the appsettings.json to DEBUG folder?

1 Answer 1

2

Found the answer in another thread is Stackoverflow(The difference between build and publish in VS?). In .NET Core, build & publish are different, as compared to .NET Framework.

Building .NET Framework applications will generate the same files as Publish. It will create all the dependencies as binaries including external dependencies(NuGets for instance). So the product of dotnet build is ready to be transferred to another machine to run

Building .NET Core applications, if the project has third-party dependencies, such as libraries from NuGet, they're resolved from the NuGet cache and aren't available with the project's built output. Therefore the product of dotnet build isn't ready to be transferred to another machine to run. You need to run Publish to get all 3rd party dependencies as binaries in output folder.

If we want a file to be part of publish, we need to add below attribute. In build, this file is not copied to the DEBUG/RELEASE folder.

<Content Include="appsettings.json">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  </Content>
Sign up to request clarification or add additional context in comments.

2 Comments

This is still only part of answer. How did you achieve (if at all you completed) to copy the appsettings.json file in Debug/Release mode?
@SivaSenthil, It has been sometime, since I worked on dotnet core. If I remember correctly, I used publish option to get the appsettings.json, to get it to publish folder, as I have mentioned in the questioni.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.