我可以通过命令行将预处理器定义传递给资源编译器吗? [英] Can I pass a preprocessor definition to the resource compiler through the command line?
问题描述
我目前正试图使用 #ifdef
标签在Visual C ++ .rc文件中的几个不同的默认图标之间切换。
I'm currently trying to switch between a few different default Icons in a Visual C++ .rc file using #ifdef
tags.
正在使用MSBuild通过命令行创建切换#define值的构建。
The builds switching the #define value are being created through command line using MSBuild.
我遇到的困难是使用Visual Studio 2010,为了将预处理器定义传递给资源编译器,必须在项目设置中定义它属性 - >资源 - >常规)。
The difficulty I have been running into is that using Visual Studio 2010, in order to pass a preprocessor definition to the resource compiler you must define it in the project settings (Config Properties -> Resources -> General).
这使得使用 #ifdef
方法它将总是在资源编译器中定义。
This makes it difficult to use an #ifdef
tag because using this method it will always be defined in the resource compiler.
我想将它定义为一个值,这样我可以使用一个预处理器 #if SOMEVALUE == 4
可能会工作,但是似乎找不到一种方式通过命令行传递一个预处理器定义+值到MSBuild。
I would love to define it to a value, so that I might use a preprocessor #if SOMEVALUE == 4
might work, but Cannot seem to find a way to pass a Preprocessor definition + value to MSBuild via the command line.
有没有人知道一种方法来传递预处理器定义直接通过资源编译器或通过命令行为msbuild定义一个预处理器定义的值的方法?
Does anyone know a way to pass a preprocessor definition directly through to the resource compiler or a way to define a value for a preprocessor definition via commandline for msbuild?
推荐答案
尝试使用环境变量将值传递到构建过程中。
Try using environment variables to pass values into your build process.
add; $(CMDLINE_DEFINES)到资源预处理器定义的末尾。 (确保选择正确的配置。)
In your project properties add ;$(CMDLINE_DEFINES) to the end of your resource preprocessor definitions. (Be sure to pick the right configuration.)
然后当您从命令行类型使用MSBuild(或添加到批处理文件)...
Then when you use MSBuild from the command line type (or add to a batch file)...
C:\Projects\SomeProject> set CMDLINE_DEFINES=SOMETEST=42
C:\Projects\SomeProject> MSBuild SomeProject.vcproj
批处理文件可能如下所示:
A batch file may look like:
@echo off
SET CMDLINE_DEFINES=%1
MSBUILD SomeProject.vcproj
使用这个批处理文件,无论你在命令行上传递什么,都将作为预处理器宏传递给构建过程。
Using this batch file, whatever you pass on the commandline will be passed on to the build process as your preprocessor macro(s).
这篇关于我可以通过命令行将预处理器定义传递给资源编译器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!