将文件复制到输出文件夹 [英] Copy files to output folder

查看:71
本文介绍了将文件复制到输出文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

要将内容文件复制到输出文件夹,可以将文件的Copy to output directory属性设置为始终复制".

或者,可以添加一个构建后事件:
XCOPY "$(ProjectDir)Templates" "$(TargetDir)" /E /I /F /Y
(或类似的内容).

问题如下:
我经常遇到与我的应用程序读取的数据文件有关的错误.通常它们与语法,缺少的分号等有关.在这种情况下,C#源代码不会在任何地方更改,因此VS不会重新编译任何内容.不会触发生成后事件,结果我必须按下"rebuild [projectname]"来强制复制内容文件.这很令人讨厌,因为:
1)有时我忘记了它并搜索不存在的错误.
2)项目越来越大,编译需要时间.

我知道一个快捷的解决方案-每次手动运行一个批处理脚本,但这并不能解决[1]问题.

=>将Build Action设置为无"并不能成功.

谢谢

问候-Jacek.

Hi!

To copy content files to an output folder, one could set the Copy to output directory property of a file to "Copy always".

Alternatively, one could add a post-build event:
XCOPY "$(ProjectDir)Templates" "$(TargetDir)" /E /I /F /Y
(or sth like that).

The problem is as following:
I often have errors related to data files which are read by my application. Usually they are related to a syntax, a missing semicolon etc. In such cases C# source code isn''t changed anywhere and therefore VS does not recompile anything. Post-build events aren''t fired and in result I have to push "rebuild [projectname]" to force copying content files. It is irritating, because:
1) sometimes I forgot about it and search for a non-existent error.
2) project is becoming bigger and bigger and a compilation takes time.

I know a quick-and-dirty solution -- manually run a batch script each time, but it wouldn''t solve [1] problem.

=> Setting a Build Action to "None" doesn''t make it.

Thanks

Greetings -- Jacek.

推荐答案

(ProjectDir)Templates"
(ProjectDir)Templates" "


(TargetDir)"/E/I/F/是
(或类似的内容).

问题如下:
我经常遇到与我的应用程序读取的数据文件有关的错误.通常它们与语法,缺少的分号等有关.在这种情况下,C#源代码不会在任何地方更改,因此VS不会重新编译任何内容.不会触发生成后事件,结果我必须按下"rebuild [projectname]"来强制复制内容文件.这很令人讨厌,因为:
1)有时我忘记了它并搜索不存在的错误.
2)项目越来越大,编译需要时间.

我知道一个快捷的解决方案-每次手动运行一个批处理脚本,但这并不能解决[1]问题.

=>将Build Action设置为无"并不能成功.

谢谢

问候-Jacek.
(TargetDir)" /E /I /F /Y
(or sth like that).

The problem is as following:
I often have errors related to data files which are read by my application. Usually they are related to a syntax, a missing semicolon etc. In such cases C# source code isn''t changed anywhere and therefore VS does not recompile anything. Post-build events aren''t fired and in result I have to push "rebuild [projectname]" to force copying content files. It is irritating, because:
1) sometimes I forgot about it and search for a non-existent error.
2) project is becoming bigger and bigger and a compilation takes time.

I know a quick-and-dirty solution -- manually run a batch script each time, but it wouldn''t solve [1] problem.

=> Setting a Build Action to "None" doesn''t make it.

Thanks

Greetings -- Jacek.


如果您将文件添加到项目中,而不是解决方案中,然后将文件的属性设置为;
构建动作=无
复制到输出目录=始终复制

设置构建动作是重要的部分,因为它告诉VS忽略构建结果并仅复制文件.
现在,当您构建项目时,即使没有代码更改,文件也会被复制到输出目录.

最后一件事,您仍然可以使用XCOPY,但可以将其作为项目的Pre-Build事件.
If you add the file to the project, not the solution, and set the properties of the file to;
Build Action = None
Copy to Output Directory = Copy always

Setting the Build Action is the important part as it tells VS to ignore the outcome of the build and just copy the file.
Now when you Build the project, the file is copied to the output directory even if no code changes.

One last thing you could still use the XCOPY but make it a Pre-Build event for the project.


这篇关于将文件复制到输出文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆