Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 741
Jeff G Avatar asked Dec 06 '25 19:12

Jeff G


2 Answers

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>
like image 152
Jeff G Avatar answered Dec 09 '25 18:12

Jeff G


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

like image 33
Dan Avatar answered Dec 09 '25 20:12

Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!