2

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.

Jeff G
  • 4,470
  • 2
  • 41
  • 76

3 Answers3

7

In the *.vcxproj file, change:

<Text Include="Filename.txt" />

to:

<Content Include="Filename.txt">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

Then in the *.vcxproj.filters file, change:

<Text Include="Filename.txt">
    <Filter>Resource Files</Filter>
</Text>

to:

<Content Include="Filename.txt">
    <Filter>Resource Files</Filter>
</Content>
Jeff G
  • 4,470
  • 2
  • 41
  • 76
5

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

Dan
  • 333
  • 4
  • 12
0

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>
Rogério Silva
  • 121
  • 1
  • 11