問題描述
我一直使用 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 項目屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!