以编程方式读取用户定义的项目宏 [英] Read user-defined project macros programmatically

查看:23
本文介绍了以编程方式读取用户定义的项目宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 C++ 源代码中读取用户定义的宏(例如 ${SolutionPath})中的 VS 项目环境变量之一?

How can I read one of VS project environment variables oder user-defined macros such as the ${SolutionPath} from source code in C++?

我刚刚创建了一个新的用户定义宏,我想在其中存储项目的当前版本.我想在构建期间使用此值并在 GUI 中显示它.您有什么更好的主意,只在一个地方存储我的产品的当前版本?

I just created a new user-defined macro where I want to store the current Version of my project. I want to use this value during build as well as to show it in the GUI. Do you have any better idea to have only one place to store the current version of my product?

似乎解决方案可能使用/D 为每个项目定义额外的预处理器标志,但我无法使用它来定义带有值的预编译器标志.

It seems like defining additional preprocessor flags for each project using /D might by a solution, but I cannot get it to work to define a precompiler flag with a value.

推荐答案

您可以使用以下格式添加额外的编译器选项

You can add an additional compiler option using the following format

/D "VariableName=\"VariableValue\""

这将使宏在项目中可用,就像您键入一样:

This will make the macro available in the project just as if you typed:

\#define VariableName VariableValue

这篇关于以编程方式读取用户定义的项目宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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