$(shell some-command)是否等效于Visual Studio项目宏? [英] $(shell some-command) equivalent for Visual Studio project macros?

查看:93
本文介绍了$(shell some-command)是否等效于Visual Studio项目宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Makefile s,我习惯于编写如下内容:

With Makefiles I'm used to being able to write things like:

includedir=$(shell pg_config --includedir)/server

运行带有参数--includedir的外部程序pg_config,并将结果包含在变量中或作为变量的一部分.因此,如果pg_config --includedir/usr/include输出到stdout,则includedir的值将变为:

to run an external program, pg_config, with argument(s) --includedir, and include the result in a variable or as part of a variable. So if pg_config --includedir output /usr/include to stdout, the value of includedir would become:

includedir=/usr/include/server

有什么方法可以对Visual Studio项目进行等效处理吗?运行命令,获取结果,并将其替换为属性?

Is there any way to do the equivalent with a Visual Studio project? Run a command, get the result, and substitute it into a property?

我发现自己不得不到处编辑属性页-每当我想针对其他PostgreSQL版本构建扩展时,都必须更改项目的x86和x64配置的包含目录和库目录.非常令人沮丧.

I find myself having to edit properties pages all over the place - changing the include directories and library directories for both the x86 and x64 configurations of a project whenever I want to build an extension against a different PostgreSQL version. It is intensely frustrating.

我希望能够将这样的内容放入配置属性-> C/C ++->常规->其他包含目录:

I want to be able to put something like this into Configuration Properties -> C/C++ -> General -> Additional Include Directories:

%(shell pg_config --includedir)

甚至更好:

%(shell %(PG_CONFIG) --includedir)

其中%(PG_CONFIG)的位置是在项目中每个平台的单个位置中定义的.

where %(PG_CONFIG)'s location is defined in a single place for each platform in the project.

因此,我正在寻找至少用户定义的宏,最好是能够调用命令行工具并将宏替换为结果标准输出的功能.

So I'm looking for at least user-defined macros, and preferably the ability to invoke a command line tool and replace the macro with the resulting standard output.

(最好是不涉及研究半文档化的UI元素,这些元素在每个VS版本中都会移动并重命名,并且会在各个Express版本中出现和消失).

(Preferably in a way that doesn't involve delving into semi-documented UI elements that move and get renamed in every VS version, and that appear and disappear from the various Express editions).

这在Makefiles中已经有20年的历史了,在VS中必须有一种方法,对吗?还是"Real Windows Developers"使用脚本生成其VS项目并使用MSBuild进行构建?

This has been possible in Makefiles for 20 years, there must be a way to do it in VS, right? Or do "Real Windows Developers" generate their VS projects with scripts and build them using MSBuild?

我看了一些类似的问题却没有发现很多用处,例如:

I've looked at some similar questions without finding much of use, e.g.:

我特别了解属性表(视图"->其他Windows"->属性管理器"),但是它们似乎并没有提供一种仅在一个地方设置值的方法,它们仍然可以配置和每个体系结构,因此,如果您有四个配置和两个体系结构,则会很尴尬.与普通项目属性编辑器不同,您甚至都不能在一组体系结构/配置中应用更改.

In particular, I'm aware of property sheets (View -> Other Windows -> Property Manager), but they don't seem to provide a way to set a value in just one place, they're still per-configuration and per-architecture, so if you have four configurations and two architectures it gets awkward. Unlike with the normal project property editor you can't even apply a change across a group of architectures/configurations, either.

我可以使用VS扩展,但是它们需要安装到用户的VS中,可以是特定于版本的,对于小问题来说似乎是一个很大的锤子.

I could use a VS extension, but they require installation into the user's VS, can be version-specific, and seem like a very big hammer for a small problem.

推荐答案

我发现自己不得不在各处编辑属性页

I find myself having to edit properties pages all over the place

那也使我无休止地烦恼.物有所值!例如,在VS10中设置主要解决方案时,我让每个项目都只包含一个设置,其中包含了包含通用设置的settings.props.然后遍历所有生成或导入的项目,并为所有可能的情况杀死任何显式值(即使为空).这样,事情将继承自属性表.选择所有配置",然后在每个配置上正确使用下拉菜单以从...继承".

That bugged me to no end as well. Property sheets to the rescue! When setting up a major solution in VS10, for example, I had every project pull in a settings.props that contained the common settings, made in only one place. Then go through all the generated or imported projects and kill any explicit value (even if blank) for everything possible. That way things will inherit from property sheets. Select "all configurations" and on each properly use the drop-down to "inherit from...".

我也为每个特殊库提供了属性表,只定义了正确的#define,包括路径,lib路径等.使用该特定外部lib的项目仅使用该属性表.在最坏的情况下,告诉用户编辑XML以将路径更改为您拥有Boost的位置".

I have property sheets for each special library too, just defining the proper #define, include paths, lib paths, etc. Projects that use that particular external lib simply use that property sheet. Users are told, in the worst case, to "edit the XML to change the path to where you have Boost".

对于将这样的值正确设置为动态确定的值,您也可以这样做.您可以使用属性函数.

As for setting such a properly to a dynamic determined value, you can do that too. There are property functions you can use.

这听起来像是您走的路和我一样.

It sounds like you're going down the same path as I did.

更多说明:属性页是根据配置/平台而定":如果您在项目本身的顶层节点(而不是Debug | Win32等子节点)上包含属性页,它将包含在所有内容中当前配置.如果您编辑正确的页面,则可以像在常规项目中使用属性"对话框一样,在属性"对话框中选择多个"或所有配置".

More notes: "prop sheets are per configuration/platform": If you include a prop sheet at the top-level node for the project itself (not the Debug|Win32, etc. child nodes) it will include it into all current configurations at once. If you edit the properly page, you can choose Multiple or All configurations on the Property dialog box, just as with the usual project use of the Property dialog.

自定义用户宏被很好地隐藏".在您创建的属性表中会显示一个属性页,但是在proj文件中打开属性对话框时(如在正常的文件视图"中一样)不会显示该属性页.宏将被放置在一个地方(prop页面),并且在包含宏的所有项目中都可以用作$(名称),甚至在评估序列后面的其他属性页中也可以使用.

"Custom user macros are well hidden" A property page shows up for that when in a property sheet you created, but not when opening property dialog on a proj file as in the normal File View. The macro will be set in one place (the prop page) and usable as a $(name) in all projects that include it, and even in other property pages that come later in the evaluation sequence.

让我知道如何进行.您应该能够完成所要求的一切.

Let me know how it goes. You should be able to do everything you asked.

—约翰

这篇关于$(shell some-command)是否等效于Visual Studio项目宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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