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 ]

Comments (3)

  1. dan (msbuild) says:

    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

  2. Romain says:


    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!



  3. Ashley Tate says:

    @Romain: The API doc comment on <a href=""&gt;

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


    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.


Skip to main content