[xbuild] Fix Tooltask.ToolPath behaviour to match .NET
authorMichael Hutchinson <m.j.hutchinson@gmail.com>
Tue, 11 Feb 2014 21:46:28 +0000 (16:46 -0500)
committerMichael Hutchinson <m.j.hutchinson@gmail.com>
Tue, 11 Feb 2014 21:46:28 +0000 (16:46 -0500)
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AL.cs
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/GenerateResource.cs
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/LC.cs
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Vbc.cs
mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs
mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs
mcs/tools/xbuild/data/2.0/Microsoft.CSharp.targets
mcs/tools/xbuild/data/3.5/Microsoft.CSharp.targets

index 6b91a2e25540927f0672b3efe56ed6afd6c1259f..1fc961b72dc1f56a4865b6a55bb1c583ef706087 100644 (file)
@@ -98,7 +98,9 @@ namespace Microsoft.Build.Tasks {
 
                protected override string GenerateFullPathToTool ()
                {
-                       return Path.Combine (ToolPath, ToolExe);
+                       if (!string.IsNullOrEmpty (ToolPath))
+                               return Path.Combine (ToolPath, ToolExe);
+                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
                }
 
                public string AlgorithmId {
@@ -234,9 +236,7 @@ namespace Microsoft.Build.Tasks {
                }
 
                protected override string ToolName {
-                       get {
-                               return MSBuildUtils.RunningOnWindows ? "al.bat" : "al";
-                       }
+                       get { return "al.exe"; }
                }
 
                public string Trademark {
index 20ad611efd3552fd134000ec232cafbd2790d8ca..142e73eddeb802dc009295d558a072bb7957652a 100644 (file)
@@ -43,6 +43,10 @@ namespace Microsoft.Build.Tasks {
 
                protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine)
                {
+#if !NET_4_0
+                       //pre-MSBuild 2 targets don't support multi-targeting, so tell compiler to use 2.0 corlib
+                       commandLine.AppendSwitch ("/sdk:2");
+#endif
                        base.AddResponseFileCommands (commandLine);
 
                        if (AdditionalLibPaths != null && AdditionalLibPaths.Length > 0)
@@ -129,11 +133,9 @@ namespace Microsoft.Build.Tasks {
 
                protected override string GenerateFullPathToTool ()
                {
-                       string exe = !string.IsNullOrEmpty (ToolExe)? ToolExe : ToolName;
-                       string path = ToolPath;
                        if (!string.IsNullOrEmpty (ToolPath))
-                               return Path.Combine (path, exe);
-                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (exe, TargetDotNetFrameworkVersion.VersionLatest);
+                               return Path.Combine (ToolPath, ToolExe);
+                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
                }
 
                [MonoTODO]
index 60dd7a68c4b8a83e0954d93d797ee53ffedb4947..8abdad3b7f7f76c0fa61469ae8074bb9487ee1e0 100644 (file)
@@ -376,7 +376,9 @@ namespace Microsoft.Build.Tasks {
 
                protected override string GenerateFullPathToTool ()
                {
-                       return Path.Combine (ToolPath, ToolExe);
+                       if (!string.IsNullOrEmpty (ToolPath))
+                               return Path.Combine (ToolPath, ToolExe);
+                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
                }
 
                protected override MessageImportance StandardOutputLoggingImportance {
@@ -384,7 +386,7 @@ namespace Microsoft.Build.Tasks {
                }
 
                protected override string ToolName {
-                       get { return MSBuildUtils.RunningOnWindows ? "resgen2.bat" : "resgen2"; }
+                       get { return "resgen.exe"; }
                }
 
                public string SourceFile { get; set; }
index 3d91d826dab29fdaa6c5215d067bb03f17b429b5..d26974c6ab76f9d2c94ab1868054c965988170ee 100644 (file)
@@ -72,7 +72,9 @@ namespace Microsoft.Build.Tasks {
 
                protected override string GenerateFullPathToTool ()
                {
-                       return Path.Combine (ToolPath, ToolExe);
+                       if (!string.IsNullOrEmpty (ToolPath))
+                               return Path.Combine (ToolPath, ToolExe);
+                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
                }
 
                protected override bool ValidateParameters()
index 80d500c16c73c4cb190274c704ff802c989392cf..107f9eb289621903f7154bed2d4c7054c70196ff 100644 (file)
@@ -141,7 +141,9 @@ namespace Microsoft.Build.Tasks {
                [MonoTODO]
                protected override string GenerateFullPathToTool ()
                {
-                       return Path.Combine (ToolPath, ToolExe);
+                       if (!string.IsNullOrEmpty (ToolPath))
+                               return Path.Combine (ToolPath, ToolExe);
+                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
                }
                
                [MonoTODO]
index 01a7c453aeca02c8be1da294dbd41d71dac98b60..ee7c37a3691958e16481e18132fabae1cbbea731 100644 (file)
@@ -72,7 +72,6 @@ namespace Microsoft.Build.Utilities
                {
                        this.TaskResources = taskResources;
                        this.HelpKeywordPrefix = helpKeywordPrefix;
-                       this.toolPath = MonoLocationHelper.GetBinDir ();
                        this.responseFileEncoding = Encoding.UTF8;
                        this.timeout = Int32.MaxValue;
                }
@@ -440,15 +439,12 @@ namespace Microsoft.Build.Utilities
                public virtual string ToolExe
                {
                        get {
-                               if (toolExe == null)
+                               if (string.IsNullOrEmpty (toolExe))
                                        return ToolName;
                                else
                                        return toolExe;
                        }
-                       set {
-                               if (!String.IsNullOrEmpty (value))
-                                       toolExe = value;
-                       }
+                       set { toolExe = value; }
                }
 
                protected abstract string ToolName
@@ -459,10 +455,7 @@ namespace Microsoft.Build.Utilities
                public string ToolPath
                {
                        get { return toolPath; }
-                       set {
-                               if (!String.IsNullOrEmpty (value))
-                                       toolPath  = value;
-                       }
+                       set { toolPath  = value; }
                }
 
                // Keep in sync with mcs/class/System/Microsoft.CSharp/CSharpCodeCompiler.cs
index 8b3ae6e69c4960c135363ad7afc0f2d5202d1c0d..a76e13f1be649eebf63266f4ee7ac3714603926d 100644 (file)
@@ -56,6 +56,23 @@ namespace MonoTests.Microsoft.Build.Utilities {
                                task.Codes.Clear ();
                        }
                }
+
+               [Test]
+               public void ToolExeAndPath ()
+               {
+                       TestToolTask a = new TestToolTask ();
+                       Assert.AreEqual (a.ToolExe, "TestTool.exe", "#1");
+                       a.ToolExe = "Foo";
+                       Assert.AreEqual (a.ToolExe, "Foo", "#2");
+                       a.ToolExe = "";
+                       Assert.AreEqual (a.ToolExe, "TestTool.exe", "#3");
+
+                       Assert.AreEqual (a.ToolPath, null, "#4");
+                       a.ToolPath = "Bar";
+                       Assert.AreEqual (a.ToolPath, "Bar", "#5");
+                       a.ToolPath = "";
+                       Assert.AreEqual (a.ToolPath, "", "#6");
+               }
        }
 
        class LogEventsFromTextOutputToolTask : ToolTask {
@@ -137,5 +154,17 @@ namespace MonoTests.Microsoft.Build.Utilities {
                        Codes.Add (e.Code);
                }
        }
+
+       class TestToolTask : ToolTask {
+
+               protected override string ToolName {
+                       get { return "TestTool.exe"; }
+               }
+
+               protected override string GenerateFullPathToTool ()
+               {
+                       throw new NotImplementedException ();
+               }
+       }
 }
 
index 66e00b8f9301ca09954746e2d77521b94c2711ec..114e862c88c897ee2574cab27ff9f6c14026268c 100644 (file)
@@ -96,9 +96,4 @@
        </Target>
 
        <Import Project="Microsoft.Common.targets" />
-
-       <PropertyGroup>
-               <CscToolExe Condition="'$(CscToolExe)' == '' and '$(OS)' == 'Unix'">gmcs</CscToolExe>
-               <CscToolExe Condition="'$(CscToolExe)' == '' and '$(OS)' != 'Unix'">gmcs.bat</CscToolExe>
-       </PropertyGroup>
 </Project>
index 66e00b8f9301ca09954746e2d77521b94c2711ec..114e862c88c897ee2574cab27ff9f6c14026268c 100644 (file)
@@ -96,9 +96,4 @@
        </Target>
 
        <Import Project="Microsoft.Common.targets" />
-
-       <PropertyGroup>
-               <CscToolExe Condition="'$(CscToolExe)' == '' and '$(OS)' == 'Unix'">gmcs</CscToolExe>
-               <CscToolExe Condition="'$(CscToolExe)' == '' and '$(OS)' != 'Unix'">gmcs.bat</CscToolExe>
-       </PropertyGroup>
 </Project>