visual-studio 始终复制到输出目录不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/495505/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy always to output directory does not work
提问by Jonas Lincoln
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.
我有一个简单的控制台项目,我正在读取两个 Excel 文件。Excel 文件包含在项目中(“添加现有项目”),我已将它们标记为“复制到输出目录”。但是,在调试/运行代码时,它们不会被复制到调试目录中。
I feel like I've forgotten something trivial. What do I need to do more?
我觉得我忘记了一些微不足道的事情。我还需要做什么?
采纳答案by Bevan
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 datechecking.
对非源代码文件的更改不会导致发生重建 - 当编译器进行过时检查时不会考虑这些更改。
Try forcing a complete rebuild by deleting your output directory completely (sometimes doing this from within Visual Studio isn't complete).
尝试通过完全删除输出目录来强制完全重建(有时在 Visual Studio 中执行此操作并不完整)。
It may be that the files haven't been copied across because a full build hasn't been run.
可能是因为尚未运行完整构建,因此文件尚未复制。
回答by Guillermo Gutiérrez
In the file properties in Visual Studio, set:
在 Visual Studio 的文件属性中,设置:
Build action: None
构建动作:无
Copy to output directory: Copy always
复制到输出目录:始终复制
回答by Scott Shaw-Smith
回答by bh213
Did you mark them as content?
您是否将它们标记为内容?
回答by Ray Booysen
Silly question but are you running in debug mode? I've made the same mistake and realised I was in release mode.
愚蠢的问题,但您是否在调试模式下运行?我犯了同样的错误并意识到我处于发布模式。
回答by Feri
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
当某些 png 文件被重命名-排除-再次添加到项目时,我遇到了问题。VS2015 似乎已经无法跟踪如何处理这些文件:尽管在 VS 中在有问题的文件中设置了“复制到输出目录:始终复制”,但 CopyToOutputDirectory 键不存在于 csproj 文件中。我不得不手动更改 csproj
<Content Include="xxx.png"/>
to this:
对此:
<Content Include="xxx.png">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
回答by John Whitmire
VS 2015 behaves similarly, not updating the output directory correctly with Content files. What doesseem 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.
VS 2015 的行为类似,未使用内容文件正确更新输出目录。 什么也似乎工作,奇怪的是,是把一个文本文件的文件夹与文件的内容,并使其内容文件也。文本文件将被复制到该目录中,所有其他内容文件也将被复制到该目录中。更奇怪的是,如果您随后删除文本文件,即使不再有要复制的原始文件,它也会继续显示在输出目录中。
回答by rswank
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.
我刚刚遇到了这个问题,出于某种原因,在项目属性下选择了“创建没有清单的应用程序”,最终将链接的内容文件复制到了构建目录。

