Copy always to output directory does not work

Visual StudioDebugging

Visual Studio Problem Overview


I've got a simple console project where I'm reading two Excel-files. The Excel-files are included in the project ("add existing item") and I've marked them with "Copy to Output Directory". However, they are not copied to the debug-directory when debugging/running the code.

I feel like I've forgotten something trivial. What do I need to do more?

Visual Studio Solutions


Solution 1 - Visual Studio

In the file properties in Visual Studio, set:

Build action: None

Copy to output directory: Copy always

Solution 2 - Visual Studio

Changes to non-source code files don't cause a rebuild to occur - they aren't considered when the compiler does it's out of date checking.

Try forcing a complete rebuild by deleting your output directory completely (sometimes doing this from within Visual Studio isn't complete).

It may be that the files haven't been copied across because a full build hasn't been run.

Solution 3 - Visual Studio

None of this worked for my WPF project. You need to mark it Content + Copy Always.

Refer to this page for details on the different Visual Studio file properties.

Solution 4 - Visual Studio

Did you mark them as content?

Solution 5 - Visual Studio

I had an issue when some png files was renamed-excluded-added again to project. It seemed that VS2015 had lost tracking what to do with these files: although in VS the "Copy to output directory: Copy always" was set at the problematic files, CopyToOutputDirectory key was not present in csproj file. I had to change csproj manually from

<Content Include="xxx.png"/>

to this:

<Content Include="xxx.png">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

Solution 6 - Visual Studio

Silly question but are you running in debug mode? I've made the same mistake and realised I was in release mode.

Solution 7 - Visual Studio

I put Content and Copy Always and it worked.

Solution 8 - Visual Studio

I just had this problem and for some reason choosing "Create application without a manifest" under the project's properties finally copied the linked content file to the build directory.

Solution 9 - Visual Studio

VS 2015 behaves similarly, not updating the output directory correctly with Content files. What does seem to work, strangely, is to put a text file in the folder with the Content files and make it a Content file also. The text file will get copied to the directory and so will all the other Content files. Stranger still, if you then delete the text file, it will continue to show up in the output directory even though there is no longer an original to be copied.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonas LincolnView Question on Stackoverflow
Solution 1 - Visual StudioGuillermo GutiérrezView Answer on Stackoverflow
Solution 2 - Visual StudioBevanView Answer on Stackoverflow
Solution 3 - Visual StudioScott Shaw-SmithView Answer on Stackoverflow
Solution 4 - Visual Studiobh213View Answer on Stackoverflow
Solution 5 - Visual StudioFeriView Answer on Stackoverflow
Solution 6 - Visual StudioRay BooysenView Answer on Stackoverflow
Solution 7 - Visual StudioI.StepView Answer on Stackoverflow
Solution 8 - Visual StudiorswankView Answer on Stackoverflow
Solution 9 - Visual StudioJohn WhitmireView Answer on Stackoverflow