Copy always to output directory does not work

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

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?

回答1:

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.



回答2:

In the file properties in Visual Studio, set:

Build action: None

Copy to output directory: Copy always



回答3:

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.



回答4:

Did you mark them as content?



回答5:

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



回答6:

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> 


回答7:

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.



回答8:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!