Welcome to MSDN Blogs Sign in | Join | Help

MSBuild in Visual Studio Part 2: How the IDE Reads Properties

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' ">

    <DebugSymbols>true</DebugSymbols>

    <DebugType>full</DebugType>

    <DefineDebug>true</DefineDebug>

    <DefineTrace>true</DefineTrace>

    <OutputPath>bin\Debug\</OutputPath>

    <DocumentationFile>WindowsApplication13.xml</DocumentationFile>

    <NoWarn>42016,41999,42017,42018,42019,42032</NoWarn>

  </PropertyGroup>

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:

Project.GlobalProperties.SetProperty(“Configuration”, “Debug”);
Project.GlobalProperties.SetProperty(“Platform”, “Any CPU”);
string outputPath = Project.EvaluatedProperties[“OutputPath”].FinalValue;

MSBuild will automatically work out all the conditionals and return the correct values. Pretty neat!

[ Author: Neil Enns ]

Published Wednesday, October 19, 2005 7:36 PM by msbuild

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Friday, January 19, 2007 3:18 AM by Konstantin Kolesnichenko

# re: MSBuild in Visual Studio Part 2: How the IDE Reads Properties

More than year passed before first comment :)

Could you describe how to read and write array of properties (list of addittional libraries for example) and send them to msbuild task after?

I couldn't find in API anything better than passing simple string :(

I mean those things, that come to msbuild task as @(AdditionalLibs) ?

Sunday, August 17, 2008 7:24 PM by MSBuild in Visual Studio | DeveloperZen

# MSBuild in Visual Studio | DeveloperZen

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker