Welcome to MSDN Blogs Sign in | Join | Help

How To: Obtain Initial Property Values in a Logger

We got a question on our MSBuild Feedback alias today that went something like this:

How do I obtain all the initial property values in the project file in my custom logger?

It's not immediately obvious from our object model, but you can do this. In the ProjectStarted event the ProjectStartedEventArgs contains a Properties member. You can iterate over this with a foreach to look at all the values of the properties in the project file.

Thanks to Dan for the question, and to Jay for the answer.

[ Author: Neil Enns ]

Published Wednesday, January 25, 2006 5:43 PM by msbuild
Filed under: ,

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 27, 2006 6:27 PM by dan (msbuild)

# re: How To: Obtain Initial Property Values in a Logger

Note that the same is true for items (and metadata). Also note this is a read-only view, because we did not want to make it too easy to write a logger that would affect the build.

-- Dan
Thursday, October 30, 2008 7:00 PM by Romain

# re: How To: Obtain Initial Property Values in a Logger

Hi,

This is very useful indeed! But there a way to retrieve the current value of a property later on during the build?

For a concrete example, here's what we want to do:

We have a logger that sends an email at the end of the build. While we can retrieve a property like $(EmailLogger_Subject) in the ProjectStarted event, it means that the build script cannot customize the email subject during the build process.

It would be really great if the ProjectFinished event had this parameter as well, to get the most up-to-date values before sending the email.

I hope this makes sense, and might be possible in a future version!

Thanks,

Romain

Thursday, January 01, 2009 11:44 AM by Ashley Tate

# re: How To: Obtain Initial Property Values in a Logger

@Romain: The API doc comment on <a href="http://msdn.microsoft.com/en-us/library/microsoft.build.framework.projectstartedeventargs.properties.aspx">

ProjectStartedEventArgs.Properties</a> indicates that you would just keep a reference to the properties object throughout the build:

<blockquote>

The property names and values accessed through Properties are kept up-to-date and can be enumerated throughout the build of the project. However, changing a property in this list will not affect the build process.

</blockquote>

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker