I've been fighting an issue with my projects that are on .NET Core and a console app. The issue is when I only modify the appsettings.json (or any other file that is marked as content) it would not copy the file to the output folder when I hit F5. To get it to copy an updated file I needed to do a rebuild.
The way I setup the files to copy to the output folder was by marking the property for
Build Action to
Copy to Output Directory to
The underlying issue is that Visual Studio likes to be the one to keep track of the modified files and it's not very good at content files. The fix, make Visual Studio not keep track of the modified files and let MSBuild do it for you.
To make Visual Studio let MSBuild determine if the project is up to date, manually edit your .csproj and add the following below one of the other
<PropertyGroup> <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> </PropertyGroup>
Also, there's an easy way to mark all files of a certain extension as content and always copy. Manually edit your .csproj and add the following:
<ItemGroup> <None Remove="*.json" /> </ItemGroup> <ItemGroup> <Content Include="*.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup>
Basically it's identical to what Visual Studio puts in there for a single file, I just changed the name to be a wildcard to match multiple files, like
*.json for all files ending in
json. If you only want it to apply to files starting with
appsettings and ending with
A full example of one of my modified .csproj files
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> <LangVersion>latest</LangVersion> <RuntimeIdentifiers>win7-x64;linux-x64</RuntimeIdentifiers> </PropertyGroup> <PropertyGroup> <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> </PropertyGroup> <ItemGroup> <None Remove="*.json" /> </ItemGroup> <ItemGroup> <Content Include="*.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> </Project>