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>

Divya · 23rd March 2020 at 2:35 pm

I m very thankful for sharing this information with us…
it helps mi a lot…..good work …keep sharing…..

Leave a Reply

Your email address will not be published. Required fields are marked *