在Visual Studio项目中,可以跨多个配置/平台设置用户宏吗? [英] In Visual Studio projects, can a user macro be set across multiple configurations/platforms?

查看:187
本文介绍了在Visual Studio项目中,可以跨多个配置/平台设置用户宏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Visual Studio中遇到的属性表,它提供了一种定义用户定义的$(MACRO)的方法一个项目.它们不是我真正想要的,但到目前为止我在VS中找不到最接近的

I've recently encountered Property Sheets in Visual Studio, which provide a way to define user defined $(MACRO)s for a project. They're not what I really want but are the closest I can find in VS so far.

但是,在属性管理器下(视图->其他Windows->属性管理器),除非您编辑特定的配置/平台组合,否则似乎无法显示配置编辑器的用户宏"部分. ,如Debug | Win32.

However, under the property manager (View -> Other Windows -> Property Manager) it doesn't seem to be possible to get the User Macros section of the configuration editor to show up unless you edit a specific configuration/platform combo, like Debug | Win32.

如果您有很多配置,并且希望(例如)将同一平台上所有配置的宏设置为相同的值,那么操作会很麻烦.

If you have quite a few configurations and want to (say) set a macro to the same value for all configurations on the same platform, this gets cumbersome fast.

通常,在编辑项目属性时,您可以选择所有配置"和/或所有平台"以将更改复制到子部分.编辑属性表时此功能不可用.

When editing project properties normally you can select "All Configurations" and/or "All Platforms" to have changes copied to sub-sections. This isn't available when editing a property sheet.

是否可以同时在属性表中为多个配置/平台设置值?例如,考虑您要为x64目标设置宏POSTGRES_INSTALL%PROGRAMFILES%\PostgreSQL\9.3,为x86目标设置%PROGRAMFILES(x86)%\PostgreSQL\9.3宏,是否可以同时为多个目标(Debug,Release,SomeCustomTarget)设置宏时间?

Is there any way to set values in a property sheet for multiple configurations/platforms at once? Consider, for example, that you want to set a macro POSTGRES_INSTALL to %PROGRAMFILES%\PostgreSQL\9.3 for x64 targets and %PROGRAMFILES(x86)%\PostgreSQL\9.3 for x86 targets, is there any way to do that for multiple targets (Debug, Release, SomeCustomTarget) at the same time?

推荐答案

属性表如何工作

属性表是属性的简单列表.条目不是按配置或按平台进行的.

How property sheets work

Property sheets are simple lists of properties. Entries aren't per-configuration or per-platform.

如果将属性表添加到项目的顶层,则会将其添加到下面的所有配置/平台组合中,就像您将属性表文件分别添加到每个配置中一样.

If you add a property sheet to the top level of a project, it's added to all configuration/platform combinations underneath, as if you individually added that property sheet file to each configuration yourself.

因此,所有属性在所有配置/平台变体中都是可见的.

All properties are therefore visible across all configuration/platform variants.

这意味着您还可以执行以下操作,例如为所有x86配置保留一张图纸,为所有x64配置保留另一张图纸,例如用于构建路径.这样,您代码中的所有其他属性都可以只使用$(MYLIB_INCLUDE)而不用担心它是32位还是64位版本.

This means you can also do things like have one sheet for all your x86 configurations and a different sheet for all your x64 configurations, e.g. for build paths. That way all the rest of your properties in your code can just use $(MYLIB_INCLUDE) without worrying about whether it's a 32- or 64-bit build.

您还可以将每个配置/平台和全局属性表有效地组合在一起,一个属性表可以在列表中进一步引用. (顺序很重要,根据用户界面,它们似乎是从下至上阅读的.)

You can usefully combine per-configuration/platform and global property sheets, too, a property sheet can reference one further down the list. (Order is significant, and they seem to be read from bottom to top according to the UI).

您可以通过以下方法检查属性的最终值:在主项目属性页中编辑属性,然后通过选项卡打开宏"(Macros>)选项卡.当调试一个用户宏从另一个工作表引用另一个用户宏的订购问题时,这很有用.

You can check what the final values of properties are by going to edit a property in the main project properties page, and tabbing open the "Macros>" tab. This is useful when debugging ordering issues with one user macro referencing another from a different sheet.

作为一个示例,您可以从pg_sysdatetime在github上的下载,我创建了三个属性床单:

As an example, which you can download from pg_sysdatetime on github here, I created three property sheets:

  • pg_sysdatetime.props 是用户的主表可以编辑以更改路径.它使用在系统上安装的32位和64位PostgreSQL的路径定义PGBASEDIR_x86PGBASEDIR_x64宏.

pg_sysdatetime_x86.props 是定义一个简单的包装器PGBASEDIR作为$(PGBASEDIR_x86).

pg_sysdatetime_x64.props

pg_sysdatetime_x64.props does the same for $(PGBASEDIR_x64)

我在项目的顶层添加了pg_sysdatetime.props,因此它已应用于所有配置/平台组合.

I added pg_sysdatetime.props to the top level of the project, so it got applied to all configuration/platform combinations.

然后我将sysdatetime_x86.props添加到所有x86平台配置中,并将sysdatetime_x64.props添加到所有x64平台配置中.

I then added sysdatetime_x86.props to all x86 platform configurations, and sysdatetime_x64.props to all x64 platform configurations.

属性编辑器如下:

在编辑属性时,我可以看到正确定义的宏:

and I can see the macros properly defined when editing a property:

现在,我可以使用简单的宏(例如:

Now I can reference the PostgreSQL libdir, include directory, etc from anywhere in my project with simple macros like:

 $(PGBASEDIR)\lib

无需关心我是要进行32位还是64位构建等.因此,我可以编辑所有配置",所有平台"的设置,并知道它们将适用于所有内容,我不必分别编辑每个人.

without caring whether I'm doing a 32-bit or 64-bit build, etc etc. So I can just edit settings for "all configurations", "all platforms" and know that they'll work for everything, I don't have to individually edit each one.

这几乎就像使用1980年的Makefile ;-)

It's almost like using a Makefile from 1980 ;-)

这篇关于在Visual Studio项目中,可以跨多个配置/平台设置用户宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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