Effective use of Visual Studio project properties for multiple projects and configurations

I have always used Visual Studios, built into the GUI support, to customize my projects, often using property sheets so that several projects use a common set.

One of my main concerns is managing multiple projects, configurations, and platforms. If you just do everything with the main graphical interface (right-click the project β†’ properties), it quickly becomes messy, difficult to error and prone to errors (for example, you cannot correctly identify any macro or use the wrong runtime library, etc.) d.). Dealing with the fact that different people put dependency libraries there in different places (for example, mine all live in "C: \ Libs \ [C, C ++] \ [lib-name] \"), and then often manage various different versions of these libraries (release, debugging, x86, x64, etc.) is also a big problem, since it greatly complicates the time it takes to configure it in the new system, and then there are problems with version control and saving all paths ..

Property sheets do this a little better, but I cannot have one sheet with separate settings for different configurations and platforms (gray drop-down boxes), as a result I have many sheets that, if inherited in the correct order, do what I want ("x86", "x64", "debug", "release", "general", "directories" (deals with the previously mentioned dependency problem, defining user macros like BoostX86LibDir, etc.) and if it is not inherited correctly (for example, β€œcommon” to β€œx64” and β€œdebug”) leads to problems such as trying to link the incorrect UIS library or incorrect naming ...

What I want is a way to deal with all these scattered dependencies and create a set of "rules" that are used by all my projects in the solution, for example, the name of the output library as "mylib- [vc90, vc100] - [x86, x64] [- d] .lib ", without having to do all this for each individual project, configuration and combination of the platform, and then synchronize them all correctly.

I am aware of the transition to completely different systems, such as CMake, which create the necessary files, but this complicates the situation in other places, making it so that even simple tasks, such as adding a new file to the project, require additional changes elsewhere, which I'm not happy either that if there are any features with VS2010 integration that can track these changes.

+59
c ++ visual-studio build visual-studio-2010 projects-and-solutions
Aug 17 '10 at 12:48
source share
6 answers

I just found out that I did not think it was possible (it is not displayed by the graphical interface), which helps to make the property sheet more useful. The Condition attribute of many tags in project properties files, and it can also be used in .props files!

I just put together the following as a test, and it did a great job and completed the task on the individual 5 property pages (general, x64, x86, debug, release)!

<?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> 

The only problem is with the GUI property handler, a project that uses the above property sheet simply passes the default values ​​to inherited values, such as "$ (project_name)" for the purpose.

+67
Aug 17 '10 at 14:50
source share

I made some improvements, may be useful for someone

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Label="UserMacros"> <!--IsDebug: search for 'Debug' in Configuration--> <IsDebug>$([System.Convert]::ToString( $([System.Text.RegularExpressions.Regex]::IsMatch($(Configuration), '[Dd]ebug'))))</IsDebug> <!--ShortPlatform--> <ShortPlatform Condition="'$(Platform)' == 'Win32'">x86</ShortPlatform> <ShortPlatform Condition="'$(Platform)' == 'x64'">x64</ShortPlatform> <!--build parameters--> <BUILD_DIR>$(registry:HKEY_CURRENT_USER\Software\MyCompany\@BUILD_DIR)</BUILD_DIR> </PropertyGroup> <Choose> <When Condition="$([System.Convert]::ToBoolean($(IsDebug)))"> <!-- debug macroses --> <PropertyGroup Label="UserMacros"> <MyOutDirBase>Debug</MyOutDirBase> <DebugSuffix>-d</DebugSuffix> </PropertyGroup> </When> <Otherwise> <!-- other/release macroses --> <PropertyGroup Label="UserMacros"> <MyOutDirBase>Release</MyOutDirBase> <DebugSuffix></DebugSuffix> </PropertyGroup> </Otherwise> </Choose> <Choose> <When Condition="Exists($(BUILD_DIR))"> <PropertyGroup Label="UserMacros"> <MyOutDir>$(BUILD_DIR)\Bin\$(MyOutDirBase)_$(ShortPlatform)\</MyOutDir> <MyIntDir>$(BUILD_DIR)\Build\$(Configuration)_$(ShortPlatform)_$(PlatformToolset)\$(ProjectGuid)\</MyIntDir> </PropertyGroup> </When> <Otherwise> <PropertyGroup Label="UserMacros"> <MyOutDir>$(SolutionDir)\Bin\$(MyOutDirBase)_$(ShortPlatform)\</MyOutDir> <MyIntDir>$(SolutionDir)\Build\$(Configuration)_$(ShortPlatform)_$(PlatformToolset)\$(ProjectGuid)\</MyIntDir> </PropertyGroup> </Otherwise> </Choose> <PropertyGroup> <OutDir>$(MyOutDir)</OutDir> <IntDir>$(MyIntDir)</IntDir> <!-- some common for projects <CharacterSet>Unicode</CharacterSet> <LinkIncremental>false</LinkIncremental> --> </PropertyGroup> </Project> 

enjoy!

+20
Feb 04 2018-11-11T00:
source share

I had the same pain for my company product (200+ projects). As I decided, this is to create a beautiful hierarchy of property sheets.

Projects inherit a property sheet by its output type, for example x64.Debug.Dynamic.Library.vsprops. This vsprops file simply inherits other property sheets using the InheritedPropertySheets attribute

 <VisualStudioPropertySheet ProjectType="Visual C++" Version="8.00" Name="x64.Debug.Dynamic.Binary" InheritedPropertySheets=".\Common.vsprops;.\x64.vsprops;.\Debug.vsprops;.\Runtime.Debug.Dynamic.vsprops;.\Output.x64.Library.vsprops" > 

You can also use variables (i.e. UserMacro, the value of which can be absolute or even environment variables) in the property sheets to customize many things based on your needs. For example, the definition of the BIN variable in Debug.vsprops

 <UserMacro name="BIN" Value="Debug" /> 

then when you set the name of the output in the vsprops series, say Output.x64.Library.vsprops

 <VisualStudioPropertySheet ProjectType="Visual C++" Version="8.00" OutputDirectory="$(BIN)" > 

The $ (BIN) variable will be expanded to what was set (in this case, Debug). Using this technique, you can easily build a beautiful hierarchy of property sheets to meet your demand.

Now one more thing you might want to do: create your own project templates that use your set of properties. The real hard part is ensuring that templates and property sheets are used correctly. My personal experience is that even if everything is set up, someone will still forget to use the template to create new projects ...

+7
Jan 11 '11 at 0:50
source share

As for the output library, you can select all your projects, then open the property pages, select "All configurations", "All platforms", and then set the target name:

$(ProjectName)-$(PlatformToolset)-$(PlatformShortName)-$(Configuration)

which will give the output, for example mylib-v100-x86-Debug.lib

We do something similar to this for additional bibliographic directories, using $(PlatformName) and #(Configuration) to select the correct library paths, although this does mean that some conflict with the initial configuration of the libraries. for example, we increased the installation of our libs to boost/lib.Win32 or boost/lib.x64 .




As for libraries and people installing them in different places, there are several options. If you have a very reliable version control system, you can just put everything in the original control, living in a folder with folders next to your source. This probably won't work if you use more than a few libraries, or if they are especially large.

Another option that comes to mind is to set an environment variable on each user computer that points to the root of their library folder, for example LIB_ROOT=c:\libraries , and then you can access this in Visual Studio as $(LIB_ROOT) .

+4
Aug 17 '10 at 12:58
source share

You can create a separate property sheet for each configuration. For this:

  • Create specification of configuration properties
  • Open Property Manager
  • Right click configuration (not the project) you want to change
  • Click "Add Existing Property Sheet" and add your sheet.

This eliminates the need to insert conditions into one sheet for multiple configurations. If you have common attributes that you would like to share between configurations, then create a hierarchy. The top sheet can be used in all configurations, and nested sheets will contain only the configuration attribute

+4
Apr 16 '12 at 18:34
source share

It seems like it's worth checking out the build tool - in my place we use a custom tool that tracks files and projects for changes and displays dependencies and compilation order. Adding a new file does not matter much - compilation is done using msbuild.

If I had to collect more than a bunch of projects, I would use something like nant: http://nant.sourceforge.net/

0
Jan 13 '11 at 19:03
source share



All Articles