复制生成过程中的Visual Studio项目文件(S)到输出目录 [英] Copying Visual Studio project file(s) to output directory during build

查看:596
本文介绍了复制生成过程中的Visual Studio项目文件(S)到输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我建立一个Visual Studio项目,可执行文件写入到项目中指定的输出目录属性页。

When I build a Visual Studio project, the executable is written to the output directory specified in the projects Property Page.

我有了一些额外的文件的项目(例如,的.ini 文件),这些程序所使用。

I have a project that has some extra files (e.g., .ini file) that are used by the program.

如何配置项目将文件复制到输出目录,以便当程序运行时,它有它的CWD其他文件的副本?

How can I configure the project to copy the file to the output directory so that when the program runs, it has a copy of the other file in its CWD?

我检查了文件的属性页,并没有什么有用的选项以外的其它从构建(这是禁用)排除它,和自定义生成工具命令是空的(再加上它是一个纯文本这并不需要任何处理文件)。

I checked the Property Page of the file and there was nothing useful other than an option to exclude it from the build (which is disabled), and the custom-build-tool command is empty (plus it is a plain-text file that does not need any processing).

推荐答案

当我在搜索文件的属性页构建行动领域,我有一个想法:设置自定义生成步骤的复制文件(手动地)。事实证明,这比我想象的更容易。我已经想通这需要使用 CMD 或其它外部可执行文件( XCOPY 的Robocopy 等),但是这不是必要的。

While I was searching the file’s Property Page for a build-action field, I had a thought: set the custom build step to copy the file (manually). This turned out to be easier than I thought. I had figured it would require using cmd or other external executable (xcopy, robocopy, etc.), but that is not necessary.

我设置的自定义生成步骤如下:

I set the Custom Build Step as follows:

Command Line : copy $(InputFileName) $(OutDir)
Description  : Copying foobar...
Outputs      : $(InputFileName)

为了设置输出字段(正确)是至关重要的,从总想着该项目是过时,需要进行重建(我不能肯定,如果它需要prefixed一起prevent VS $(OUTDIR)\\ )。

Setting the outputs field (correctly) was critical in order to prevent VS from always thinking the project is out of date and requiring to be rebuilt (I’m not certain if it needs to be prefixed with $(OutDir)\).

据反映在输出窗口,例如:

It is reflected in the Output window as such:

Copying foobar...
        1 file(s) copied.
Compiling resources...
Linking...

这篇关于复制生成过程中的Visual Studio项目文件(S)到输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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