Visual Studio C ++项目管理。如何处理项目中的非代码文件?

时间:2021-10-11 19:52:01

I have a project in a c++ solution. For that project, I have some config files that I would like to manage from within the project and when I build the project, have those config files added to the executable build path in the proper directory structure.

我有一个c ++解决方案的项目。对于该项目,我有一些我想在项目中管理的配置文件,当我构建项目时,将这些配置文件添加到正确的目录结构中的可执行构建路径中。

Example:

test.exe references config/myconfig.txt

test.exe引用config / myconfig.txt

Is there a way to setup myconfig.txt and my project so when I build test.exe, I get

有没有办法设置myconfig.txt和我的项目所以当我构建test.exe时,我得到了

/

as well as

以及

//config/config.txt

so when I run test, all paths stay in the proper order without me having to go in and manually create those directories.

因此,当我运行测试时,所有路径都保持正确的顺序,而我不必进入并手动创建这些目录。

I'm not sure I'm making sense here, but maybe one of you will understand where I'm going.

我不确定我在这里有意义,但也许你们其中一个人会明白我要去哪里。

2 个解决方案

#1


6  

You could use pre-build events to create the directories and copy the files.

您可以使用预构建事件来创建目录并复制文件。

#2


0  

In Visual Studio's Solution Explorer, you can right-click on the non-code files, select "Properties" and set the "Copy To Output Directory" property.

在Visual Studio的解决方案资源管理器中,您可以右键单击非代码文件,选择“属性”并设置“复制到输出目录”属性。

This creates a rule in the build file to (1) include the file, and (2) to copy that file as part of the build process. In other words, it's possible to get this behavior without Visual Studio, but a little more work.

这将在构建文件中创建一条规则,以(1)包含该文件,以及(2)将该文件作为构建过程的一部分进行复制。换句话说,可以在没有Visual Studio的情况下获得此行为,但需要更多工作。

#1


6  

You could use pre-build events to create the directories and copy the files.

您可以使用预构建事件来创建目录并复制文件。

#2


0  

In Visual Studio's Solution Explorer, you can right-click on the non-code files, select "Properties" and set the "Copy To Output Directory" property.

在Visual Studio的解决方案资源管理器中,您可以右键单击非代码文件,选择“属性”并设置“复制到输出目录”属性。

This creates a rule in the build file to (1) include the file, and (2) to copy that file as part of the build process. In other words, it's possible to get this behavior without Visual Studio, but a little more work.

这将在构建文件中创建一条规则,以(1)包含该文件,以及(2)将该文件作为构建过程的一部分进行复制。换句话说,可以在没有Visual Studio的情况下获得此行为,但需要更多工作。