在构建期间将 Visual Studio 项目文件复制到输出目录 [英] Copying Visual Studio project file(s) to output directory during build

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

问题描述

当我构建 Visual Studio 项目时,可执行文件被写入项目属性页中指定的输出目录.

我有一个项目,其中包含一些程序使用的额外文件(例如 .ini 文件).

如何配置项目以将文件复制到输出目录,以便在程序运行时,它的 CWD 中有另一个文件的副本?

我检查了文件的属性页,除了从构建中排除它的选项(已禁用)之外,没有任何有用的东西,并且 custom-build-tool 命令是空的(而且它是一个纯文本不需要任何处理的文件).

解决方案

当我在文件的属性页中搜索构建操作字段时,我有一个想法:将自定义构建步骤设置为 copy 文件(手动).结果证明这比我想象的要容易.我认为这需要使用 cmd 或其他外部可执行文件(xcopyrobocopy 等),但这不是必需的.

我将自定义构建步骤设置如下:

命令行:复制 $(InputFileName) $(OutDir)描述:复制 foobar...输出:$(InputFileName)

设置输出字段(正确)是至关重要的,以防止 VS 总是认为项目已过时并需要重建(我不确定它是否需要以 $(OutDir)).

它反映在输出窗口中,如下所示:

正在复制 foobar...已复制 1 个文件.编译资源...正在链接...

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

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

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).

解决方案

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)

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 项目文件复制到输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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