When creating a console application I normally mimic ASP.NET core apps and keep my configuration settings in an appsettings.json file. When publishing the application in Visual Studio the appsettings.json file needs to have it’s properties updated to ensure it’s copied to the publish folder like so.
Doing this updates the projects csproj file with the following entry telling it to copy the file to the publish folder.
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Unfortunatly it’s not quite as obvious in Visual Code and the above code doesn’t work but after a bit of trial and error I figured out that the below code should be used instead. This also works to copy any other external files to the output folder.
<ItemGroup>
<None Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
0 Comments