Reevaluation of project.

This code will not cause reevaluation of project's data:

BuildProperty a,b;

string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<Name>Value</Name>
</PropertyGroup>
</Project>
";

engine = new Engine (binPath);

project = engine.CreateNewProject ();
project.LoadXml (documentString);

a = project.EvaluatedProperties ["Name"];

b = a.Clone (false);

b.Value = "AnotherValue";


If I try to get a.Value again I get "Value" instead of "AnotherValue". It's easy to check that project.Xml shows changed value. If I create a new project from old project.Xml I'll get what I want.

Is it by design


Answer this question

Reevaluation of project.

  • Mihiri

    I'm checking project.Xml by Console.WriteLine () just after/before checking a.Value.

    "create new project" I meant:
    string oldProjectString = project.Xml;
    newProject = engine.CreateNewProject ();
    newProject.LoadXml (oldProjectString);

    then I check in the same way as last time.

    I think that I also checked assigning "a" value once again (=project.EvaluatedProperties...) and I got the same old value (Value not AnotherValue).

  • Bonzo the Beginner

    Hi Marek

    I tried to reproduce the problem you describe but the behavior I get is slightly different.

    Like you said, if I try to get a.Value again, I get "Value" and not another value. This is because even though we are making a shallow copy of a into b, since strings are immutable in .net, a new string is created and referenced by b, while a still has a reference to the old string, therefore its value does not change.

    However, when I try to get the value of the property again from the project by callling project.EvaluatedProperties["Name"], I get "Value". How are you checking "project.Xml"

    I am sorry I also don't understand what you mean by "If I create a new project from old project.Xml I'll get what I want." Can you please clarify

    Thanks,


  • Reevaluation of project.