Visual Studio 2017 C++ Project Copy Text Files to Output Directory

Viewed 2971

I have a number of *.txt files included in my Visual Studio 2017 C++ project (*.vcxproj). Does anyone know how to get Visual Studio to copy these files to the output directory?

I found a similar question for VS 2010, but that answer doesn't work in Visual Studio 2017.

3 Answers

Update for 2019 users:

An easy way to do this is from the file's Property Pages (right-click on the file in Solution Explorer, then click Properties).

Under Configuration Properties > General, change Item Type to "Copy file." By default, this will create a copy of the file in the build destination directory. Once you hit Apply, a new property page called Copy File will appear on the left where you can customize this behavior.

Configuration Properties Page

In a VS2019 c++ console project it was just a litlle different:

<ItemGroup>
    <None Include="Run.bat">
      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
      <DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>

      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

    </None>
  </ItemGroup>
Related