Many of the properties in an MSBuild project file show up directly within the Visual Studio environment. The most common place you’ll see the properties show up is in the project properties screen:
How do these properties get from the MSBuild XML in the project file into the dialog? Well, as you might guess, the project system uses methods on the MSBuild object model. You might think it’s as straightforward as just asking for the property from the file, but notice those two pesky drop-downs in the screenshot for configuration and platform. Somehow the project system needs to get different values back from the project file depending on what the user has picked for configuration and platform.
If you crack open a project file you can see how all these settings are stored. Here’s a snippet from a VB project file with the settings for the Debug|Any CPU configuration:
<PropertyGroup Condition=“ ‘$(Configuration)|$(Platform)’ == ‘Debug|AnyCPU’ “>
Notice the conditional on the PropertyGroup element. To get back the values for that section, the project system first sets the Configuration and Platform properties to Debug and Any CPU, then retrieves the rest of the properties. The code looks something like this:
MSBuild will automatically work out all the conditionals and return the correct values. Pretty neat!
[ Author: Neil Enns ]