Detect changes to Project metadata by MSBuild RRS feed

  • Question

  • project attributes are not removed immediately or at all after the ProjectElement.RemoveFromProjectFile() call. 
    I notice that the removal procedure is asynchronous from ProjectElement.RemoveFromProjectFile() method. 

    I have tested with the following code, which uses the dirty flag to detect with MSBuild has updated the project metadata, and tries to
    save the changes into disk. However I cannot determine a time which I can reliably tell MSBuild has completed the work. 

    The following code is in a subclass of ProjectNode.cs

    int x = some time in millisecond            
          this.IsDirty(out dirtyFlag);
    while (dirtyFlag == 0);

    Empirical testing showed 70-80% of the time, the dirty flag is set within 1 second from the ProjectElement.RemoveFromProjectFile() call.
    However the remaining 20% can reach up to 10 seconds without any indication. Is there another way for me to detect MSBuild events, and
    trigger off that? Example of such use is to save updated project changes to disk.
    Thursday, February 4, 2010 11:17 PM


  • Hello, Joe

    No other way, ProjectElement.RemoveFromProjectFile

    As far as I invested it is reliable, it is not asynchronous as what you have said.

    Since MPF is open source, so you could reference its code. It’s code doen’t start another thread or use something that start a new thread.

            public void RemoveFromProjectFile()


                if(!deleted && item != null)


                    deleted = true;



                itemProject = null;

                item = null;


    And I have done a test, I use ProjectElement.RemoveFromProjectFile in my code, method and I have add itemProject.BuildProject.IsDirty to its watch window. Before the project item is removed, the expression value is fales, but after execute itemProject.BuildProject.RemoveItem(item), it is turn true immediately.

    Please try to watch it in a watch window, and let me know the result.



    • Marked as answer by Chao Kuo Wednesday, February 10, 2010 2:48 AM
    Monday, February 8, 2010 9:23 AM