How to Copy Files to the Output Directory in .NET

When writing blog posts, I sometimes create an application that needs to read a local file from the project directory. But that file is not copied to the output directory by default, so I end up with missing file errors.

The example below will copy all text files to the build output directory, add it to the .csproj file.

<ItemGroup>
  <None Update="*.txt">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup> 

That’s all there is to it.

comments powered by Disqus

Related