From 86d1bc5fee3fc6b9166f58a8898ad23612bb0cd1 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 23 Oct 2013 04:22:07 +0900 Subject: [PATCH] Fix MSBuildThisFile reserved property value (empty by default). --- .../Microsoft.Build.Evaluation/Project.cs | 2 +- .../ExpressionEvaluator.cs | 4 +- .../ResolvedImportTest.cs | 45 ++++++++++++++++--- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/Project.cs b/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/Project.cs index c0d78cfe128..77b642873e0 100644 --- a/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/Project.cs +++ b/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/Project.cs @@ -651,7 +651,7 @@ namespace Microsoft.Build.Evaluation internal string GetEvaluationTimeThisFile () { - return ProjectCollection.OngoingImports.Count > 0 ? ProjectCollection.OngoingImports.Peek () : FullPath; + return ProjectCollection.OngoingImports.Count > 0 ? ProjectCollection.OngoingImports.Peek () : FullPath ?? string.Empty; } } } diff --git a/mcs/class/Microsoft.Build/Microsoft.Build.Internal/ExpressionEvaluator.cs b/mcs/class/Microsoft.Build/Microsoft.Build.Internal/ExpressionEvaluator.cs index af57021422e..97b29a1c4a6 100644 --- a/mcs/class/Microsoft.Build/Microsoft.Build.Internal/ExpressionEvaluator.cs +++ b/mcs/class/Microsoft.Build/Microsoft.Build.Internal/ExpressionEvaluator.cs @@ -71,7 +71,7 @@ namespace Microsoft.Build.Internal throw new InvalidProjectFileException (string.Format ("Recursive reference to item '{0}' with include '{1}' was found", item.ItemType, item.UnevaluatedInclude)); try { items.Add (item); - // FIXME: needs verification if string evaluation is appropriate. + // FIXME: needs verification on whether string evaluation is appropriate or not. return Evaluator.Evaluate (item.UnevaluatedInclude); } finally { items.Remove (item); @@ -84,7 +84,7 @@ namespace Microsoft.Build.Internal throw new InvalidProjectFileException (string.Format ("Recursive reference to property '{0}' was found", prop.Name)); try { props.Add (prop); - // FIXME: needs verification if string evaluation is appropriate. + // FIXME: needs verification on whether string evaluation is appropriate or not. return Evaluator.Evaluate (prop.UnevaluatedValue); } finally { props.Remove (prop); diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs index 49abb7c6780..10061a431d3 100644 --- a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs @@ -13,6 +13,8 @@ namespace MonoTests.Microsoft.Build.Evaluation [TestFixture] public class ResolvedImportTest { + const string temp_file_name = "test_imported.proj"; + [Test] public void SimpleImportAndSemanticValues () { @@ -28,12 +30,12 @@ namespace MonoTests.Microsoft.Build.Evaluation "; - using (var ts = File.CreateText ("test_imported.proj")) + using (var ts = File.CreateText (temp_file_name)) ts.Write (imported); try { var reader = XmlReader.Create (new StringReader (xml)); var root = ProjectRootElement.Create (reader); - Assert.AreEqual ("test_imported.proj", root.Imports.First ().Project, "#1"); + Assert.AreEqual (temp_file_name, root.Imports.First ().Project, "#1"); var proj = new Project (root); var prop = proj.GetProperty ("A"); Assert.IsNotNull (prop, "#2"); @@ -42,7 +44,7 @@ namespace MonoTests.Microsoft.Build.Evaluation Assert.IsNotNull (item, "#4"); Assert.AreEqual ("included.txt", item.EvaluatedInclude, "#5"); } finally { - File.Delete ("imported.proj"); + File.Delete (temp_file_name); } } @@ -68,7 +70,7 @@ namespace MonoTests.Microsoft.Build.Evaluation void ImportAndPropertyOverrides (string label, string condition, string valueA, string valueB, string valueAPredecessor, bool existsC) { - using (var ts = File.CreateText ("test_imported.proj")) + using (var ts = File.CreateText (temp_file_name)) ts.Write (import_overrides_test_imported); try { string xml = string.Format (import_overrides_test_xml, condition); @@ -95,7 +97,7 @@ namespace MonoTests.Microsoft.Build.Evaluation else Assert.IsNull (c, label + "#8"); } finally { - File.Delete ("test_imported.proj"); + File.Delete (temp_file_name); } } @@ -107,6 +109,39 @@ namespace MonoTests.Microsoft.Build.Evaluation ImportAndPropertyOverrides ("[3]", "$(B)=='Y'", "X", "Y", null, false); // evaluated as false ImportAndPropertyOverrides ("[4]", "$(B)=='b'", "X", "Y", null, false); // of course not evaluated with imported value } + + // FIXME: + // Looks like $(MSBuildThisFile) is available only within property value, not via .NET MSBuild API. + // Right now our variable is added as a Reserved property, but we will have to hide it. + // + [Test] + public void EvaluateMSBuildThisFileProperty () + { + string xml = @" + + $(MSBuildThisFile) + + +"; + string imported = @" + + $(MSBuildThisFile) + +"; + using (var ts = File.CreateText (temp_file_name)) + ts.Write (imported); + try { + var reader = XmlReader.Create (new StringReader (xml)); + var root = ProjectRootElement.Create (reader); + var proj = new Project (root); + var a = proj.GetProperty ("A"); + Assert.AreEqual (string.Empty, a.EvaluatedValue, "#1"); + var b = proj.GetProperty ("B"); + Assert.AreEqual (temp_file_name, b.EvaluatedValue, "#2"); + } finally { + File.Delete (temp_file_name); + } + } } } -- 2.25.1