问题描述
我一直使用 Visual Studios 内置的 GUI 支持来配置我的项目,经常使用属性表,以便多个项目使用一个公共集.
I have always used Visual Studios built in GUI support for configuring my projects, often using property sheets so that several projects will use a common set.
我对此的主要抱怨之一是管理多个项目、配置和平台.如果您只是使用主 GUI 完成所有操作(右键单击项目 -> 属性),它很快就会变得一团糟,难以维护并且容易出现错误(例如无法正确定义某些宏,或使用错误的运行时库等).处理不同的人将依赖库放在不同地方的事实(例如我的都住在C:Libs[C,C++][lib-name]")然后经常管理这些库的不同版本不同的(发布、调试、x86、x64 等)也是一个大问题,因为它使在新系统上设置它的时间大大复杂化,然后存在版本控制和保持每个人的路径分开的问题..
One of my main gripes with this is managing multiple projects, configurations and platforms. If you just do everything with the main GUI (right click the project -> properties) it quickly becomes a mess, difficult to maintain and prone to bugs (like failing to correctly define some macro, or using the wrong runtime library, etc). Dealing with the fact that different people put there dependency libraries in different places (eg mine all live in "C:Libs[C,C++][lib-name]") and then often manage the different versions of those libraries differently as well (release, debug, x86, x64, etc) is also a large problem since it vastly complicates the time to set it up on a new system, and then there is issues with version-control and keeping everyone's paths separate...
属性表让这更好一点,但我不能让一张表对不同的配置和平台有单独的设置(下拉框变灰),导致我有很多表,如果以正确的顺序继承,可以做什么我想要(x86"、x64"、debug"、release"、common"、directories"(通过定义像 BoostX86LibDir 这样的用户宏来处理前面提到的依赖问题),如果继承错误顺序(例如x64"和调试"之前的通用")会导致诸如尝试链接不正确的库版本或错误地命名输出之类的问题...
Property sheets make this a bit better, but I cant have one sheet have separate settings for different configurations and platforms (the drop down boxes a greyed out), resulting in me having many sheets which if inherited in the correct order do what I want ("x86", "x64", "debug", "release", "common", "directories" (deals with the previously mentioned dependency issue by defining user macros like BoostX86LibDir), etc) and if inherited in the wrong order (eg "common" before "x64" and "debug") lead to issues like trying to link an incorrect library version, or incorrectly naming the output...
我想要的是一种处理所有这些分散的依赖项并设置一组规则"的方法,这些规则被解决方案中的所有项目使用,例如将输出库命名为mylib-[vc90,vc100]-[x86,x64][-d].lib",无需为每个单独的项目、配置和平台组合做所有这些,然后让它们全部正确同步.
What I want is a way of dealing with all these scattered dependencies and setting up a set of "rules" which are used by all my projects in the solution, like naming an output library as "mylib-[vc90,vc100]-[x86,x64][-d].lib", without having to do all this for each individual project, configuration and platform combination, and then keep them all correctly in sync.
我知道转移到完全不同的系统,如创建所需文件的 CMake,但是这会使其他地方的事情复杂化,因为即使是简单的任务,如向项目添加新文件,然后需要在其他地方进行额外的更改,这不是我对两者都非常满意,除非有一些与 VS2010 集成可以跟踪这些类型的变化.
I am aware of moving to entirely different systems like CMake that create the needed files, however this then complicates things elsewhere by making it so even simple tasks like adding a new file to the project then requires additional changes elsewhere, which is not something I am entirely happy with either, unless there is some with VS2010 integration which can keep track of these sorts of changes.
推荐答案
我刚刚发现了一些我认为不可能的东西(它不是由 GUI 公开的),这有助于使属性表更有用.项目属性文件中许多标签的条件"属性,它也可以在 .props 文件中使用!
I just found out somthing I didnt think was possible (it is not exposed by the GUI) that helps make property sheet far more useful. The "Condition" attribute of many of the tags in the project property files and it can be used in the .props files as well!
我只是将以下内容放在一起作为测试,效果很好,并完成了 5 个(通用、x64、x86、调试、发布)单独属性表的任务!
I just put together the following as a test and it worked great and did the task of 5 (common,x64,x86,debug,release) separate property sheets!
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="UserMacros">
<!--debug suffix-->
<DebugSuffix Condition="'$(Configuration)'=='Debug'">-d</DebugSuffix>
<DebugSuffix Condition="'$(Configuration)'!='Debug'"></DebugSuffix>
<!--platform-->
<ShortPlatform Condition="'$(Platform)' == 'Win32'">x86</ShortPlatform>
<ShortPlatform Condition="'$(Platform)' == 'x64'">x64</ShortPlatform>
<!--toolset-->
<Toolset Condition="'$(PlatformToolset)' == 'v90'">vc90</Toolset>
<Toolset Condition="'$(PlatformToolset)' == 'v100'">vc100</Toolset>
</PropertyGroup>
<!--target-->
<PropertyGroup>
<TargetName>$(ProjectName)-$(Toolset)-$(ShortPlatform)$(DebugSuffix)</TargetName>
</PropertyGroup>
</Project>
唯一的问题是属性 GUI 无法处理它,使用上述属性表的项目只会报告目标的默认继承值,例如$(ProjectName)".
Only issue is the properties GUI cant handle it, a project that uses the above property sheet just reports default inherited values like "$(ProjectName)" for the target.
这篇关于对多个项目和配置有效地使用 Visual Studio 项目属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!