using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
+using System.Collections;
namespace Microsoft.Build.Evaluation
{
void ProcessXml ()
{
+ foreach (DictionaryEntry p in Environment.GetEnvironmentVariables ())
+ this.properties.Add (new EnvironmentProjectProperty (this, (string) p.Key, (string) p.Value));
+ foreach (var p in GlobalProperties)
+ this.properties.Add (new GlobalProjectProperty (this, p.Key, p.Value));
foreach (var child in Xml.Children) {
if (child is ProjectPropertyGroupElement)
foreach (var p in ((ProjectPropertyGroupElement) child).Properties)
Environment
}
- internal class XmlProjectProperty : ProjectProperty
+ internal abstract class BaseProjectProperty : ProjectProperty
{
- public XmlProjectProperty (Project project, ProjectPropertyElement xml, PropertyType propertyType)
+ public BaseProjectProperty (Project project, PropertyType propertyType)
: base (project)
{
- this.xml = xml;
property_type = propertyType;
}
- ProjectPropertyElement xml;
PropertyType property_type;
public override bool IsEnvironmentProperty {
public override bool IsReservedProperty {
get { return property_type == PropertyType.Reserved; }
}
- public override string Name {
- get { return xml.Name; }
- }
public override ProjectProperty Predecessor {
get {
throw new NotImplementedException ();
}
}
+ }
+
+ internal class XmlProjectProperty : BaseProjectProperty
+ {
+ public XmlProjectProperty (Project project, ProjectPropertyElement xml, PropertyType propertyType)
+ : base (project, propertyType)
+ {
+ this.xml = xml;
+ }
+
+ ProjectPropertyElement xml;
+
+ public override string Name {
+ get { return xml.Name; }
+ }
public override string UnevaluatedValue {
get { return xml.Value; }
set { xml.Value = value; }
get { return xml; }
}
}
+
+ internal class EnvironmentProjectProperty : BaseProjectProperty
+ {
+ public EnvironmentProjectProperty (Project project, string name, string value)
+ : base (project, PropertyType.Environment)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ readonly string name, value;
+
+ public override string Name {
+ get { return name; }
+ }
+ public override string UnevaluatedValue {
+ get { return value; }
+ set { throw new InvalidOperationException (string.Format ("You cannot change value of environment property '{0}'.", Name)); }
+ }
+ public override ProjectPropertyElement Xml {
+ get { return null; }
+ }
+ }
+
+ internal class GlobalProjectProperty : BaseProjectProperty
+ {
+ public GlobalProjectProperty (Project project, string name, string value)
+ : base (project, PropertyType.Global)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ readonly string name, value;
+
+ public override string Name {
+ get { return name; }
+ }
+ public override string UnevaluatedValue {
+ get { return value; }
+ set { throw new InvalidOperationException (string.Format ("You cannot change value of global property '{0}'.", Name)); }
+ }
+ public override ProjectPropertyElement Xml {
+ get { return null; }
+ }
+ }
}
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using NUnit.Framework;
+using System.Collections.Generic;
namespace MonoTests.Microsoft.Build.Evaluation
{
<Item/>
</PropertyGroup>
</Project>";
- var path = "file://localhost/foo.xml";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var pe = root.Properties.First ();
prop.UnevaluatedValue = "x";
Assert.AreEqual ("x", pe.Value, "#3");
}
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void UpdateGlobalPropertyValue ()
+ {
+ string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
+ var xml = XmlReader.Create (new StringReader (project_xml));
+ var props = new Dictionary<string, string> ();
+ props.Add ("GP", "GV");
+ var root = ProjectRootElement.Create (xml);
+ var proj = new Project (root, props, null);
+ var pe = proj.Properties.First (p => p.IsGlobalProperty);
+ pe.UnevaluatedValue = "UPDATED";
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void UpdateEnvironmentPropertyValue ()
+ {
+ string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
+ var xml = XmlReader.Create (new StringReader (project_xml));
+ var root = ProjectRootElement.Create (xml);
+ var proj = new Project (root);
+ var pe = proj.Properties.First (p => p.IsEnvironmentProperty);
+ pe.UnevaluatedValue = "UPDATED";
+ }
}
}