Search code examples
msbuildvcxproj

MSBuild Shorten Configuration Managment In vcxproj-Files


  • Windows Version: Microsoft Windows [Version 10.0.14393]
  • MSBuild Version : Microsoft (R)-Buildmodul, Version 15.1.1012.6693
  • The project is written in C.

In the *.vcxproj files of this project there is a lot of code in like this

<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  [do some stuff]
</ImportGroup>

for all configurations, 'Debug|Win32', 'Release|Win32', 'Debug|x64', 'Release|x64'. But I will have the same configuration for all combinations, therefore I do not want to write it 4 times making my project file 3 times longer and less readable .

Is there a shortcut like Condition="'$(Configuration)|$(Platform)'=='Any Configuration|Any Architecture'?


Solution

  • The standard way of doing this would be using 'property sheets'; more concrete: one property sheet with the common options which gets imported by all platform/configuration combinations. Some reasons to choose this approach:

    • it exactly addresses your "I will have the same configuration for all combinations, therefore I do not want to write it 4 times making my project file 3 times longer and less readable" requirement, and more: it keeps the common options in one single file, which can also be resued by other projects (which is really the number 1 selling point if you have multiple projects and want the same options for them)
    • it has user interface support for editing (though it's no problem if you'd want to manually edit the vcxproj to add it)
    • it keeps the standard project structure intact, so still allows for per-configuration and per-platform modifications should you need those
    • property sheets are just msbuild files like any other and as such can Import other files so you can create hierarchies with them, do things like having one master file which based on application type (exe/dll) sets different output paths and so on