Correctly handle precedence of ToolsVersion value coming
authorAnkit Jain <radical@corewars.org>
Fri, 9 Jul 2010 14:56:14 +0000 (14:56 -0000)
committerAnkit Jain <radical@corewars.org>
Fri, 9 Jul 2010 14:56:14 +0000 (14:56 -0000)
from various points.
In class/Microsoft.Build.Engine:

* Microsoft.Build.Engine.dll.sources: Add
UnknownToolsVersionException.cs

In class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine:

Correctly handle precedence of ToolsVersion value coming
from various points.
* BuildEngine.cs (BuildProjectFile): Restore project.ToolsVersion .
* Engine.cs: Likewise. Also validate DefaultToolsVersion .
* Project.cs: Handle invalid tools version specified in the project
file, and fall back to engine's version.
* MSBuild.cs: Fix the precedence order, and validate.
* UnknownToolsVersionException.cs: New.

In class/Microsoft.Build.Tasks:

* Microsoft.Build.Tasks.dll.sources: Use
UnknownToolsVersionException.cs from Engine.

In class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks:

* MessageTest (TestExecution): Additional messages with 'low'
importance get emitted, so don't expect sequential messages.

In tools/xbuild:

* Main.cs: Use tools version specified on the command line, if
any.
* xbuild.exe.sources: Include UnknownToolsVersionException.cs from
MS.B.Engine

svn path=/trunk/mcs/; revision=160133

15 files changed:
mcs/class/Microsoft.Build.Engine/ChangeLog
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildEngine.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UnknownToolsVersionException.cs [new file with mode: 0644]
mcs/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources
mcs/class/Microsoft.Build.Tasks/ChangeLog
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks.dll.sources
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/MessageTest.cs
mcs/tools/xbuild/ChangeLog
mcs/tools/xbuild/Main.cs
mcs/tools/xbuild/xbuild.exe.sources

index 11e68a370628fc9b45c384116563fe0157412d73..fdd1a9ef402af94c54cad8e3c5584e825b73a978 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-09  Ankit Jain  <jankit@novell.com>
+
+       * Microsoft.Build.Engine.dll.sources: Add
+       UnknownToolsVersionException.cs
+
 2010-04-06  Ankit Jain  <jankit@novell.com>
 
        * Makefile (EXTRA_DISTFILES): Remove TestTasks.dll.config .
index 1d48f9225010aadade0d0b31318024bfec47bca3..1aa15b6909ab7e9209b1ce41687a906aa9af6bc3 100644 (file)
@@ -69,9 +69,14 @@ namespace Microsoft.Build.BuildEngine {
                                       IDictionary targetOutputs, string toolsVersion)
                {
                        if (String.IsNullOrEmpty (projectFileName)) {
+                               string oldProjectToolsVersion = project.ToolsVersion;
                                project.ToolsVersion = toolsVersion;
-                               return engine.BuildProject (project, targetNames, targetOutputs,
+                               try {
+                                       return engine.BuildProject (project, targetNames, targetOutputs,
                                                BuildSettings.DoNotResetPreviouslyBuiltTargets);
+                               } finally {
+                                       project.ToolsVersion = oldProjectToolsVersion;
+                               }
                        } else {
                                BuildPropertyGroup bpg = new BuildPropertyGroup ();
                                if (globalProperties != null)
index a3b98f8d57db193915987142bd754c0afa8f5698..7cd5a01f3fccbbdfd2c04fb2dff2f38d5504b6a0 100644 (file)
@@ -1,3 +1,14 @@
+2010-07-09  Ankit Jain  <jankit@novell.com>
+
+       Correctly handle precedence of ToolsVersion value coming
+       from various points.
+       * BuildEngine.cs (BuildProjectFile): Restore project.ToolsVersion .
+       * Engine.cs: Likewise. Also validate DefaultToolsVersion .
+       * Project.cs: Handle invalid tools version specified in the project
+       file, and fall back to engine's version.
+       * MSBuild.cs: Fix the precedence order, and validate.
+       * UnknownToolsVersionException.cs: New.
+
 2010-06-23  Ankit Jain  <jankit@novell.com>
 
        * TargetBatchingImpl.cs (BuildTargetNeeded): Fix var names to
index e211551f9c7a469620d7a5694c41fa32744df5f2..8c8a03b6145a44f84d71384b201094ca182bccaf 100644 (file)
@@ -104,7 +104,6 @@ namespace Microsoft.Build.BuildEngine {
                        this.Toolsets = new ToolsetCollection ();
                        LoadDefaultToolsets ();
                        defaultTasksTableByToolsVersion = new Dictionary<string, TaskDatabase> ();
-                       GetDefaultTasks (DefaultToolsVersion);
                }
 
                //FIXME: should be loaded from config file
@@ -248,14 +247,21 @@ namespace Microsoft.Build.BuildEngine {
                        }
 
                        try {
+                               string oldProjectToolsVersion = project.ToolsVersion;
                                if (String.IsNullOrEmpty (toolsVersion) && defaultToolsVersion != null)
-                                       // it has been explicitly set, xbuild does this..
-                                       //FIXME: should this be cleared after building?
+                                       // no tv specified, let the project inherit it from the
+                                       // engine. 'defaultToolsVersion' will be effective only
+                                       // it has been overridden. Otherwise, the project's own
+                                       // tv will be used.
                                        project.ToolsVersion = defaultToolsVersion;
                                else
                                        project.ToolsVersion = toolsVersion;
 
-                               return project.Build (targetNames, targetOutputs, buildFlags);
+                               try {
+                                       return project.Build (targetNames, targetOutputs, buildFlags);
+                               } finally {
+                                       project.ToolsVersion = oldProjectToolsVersion;
+                               }
                        } finally {
                                if (globalProperties != null) {
                                        GlobalProperties = engine_old_grp;
@@ -427,7 +433,7 @@ namespace Microsoft.Build.BuildEngine {
 
                        var toolset = Toolsets [toolsVersion];
                        if (toolset == null)
-                               throw new Exception ("Unknown toolsversion: " + toolsVersion);
+                               throw new UnknownToolsVersionException (toolsVersion);
 
                        string toolsPath = toolset.ToolsPath;
                        string tasksFile = Path.Combine (toolsPath, defaultTasksProjectName);
@@ -502,7 +508,11 @@ namespace Microsoft.Build.BuildEngine {
                                
                                return defaultToolsVersion;
                        }
-                       set { defaultToolsVersion = value; }
+                       set {
+                               if (Toolsets [value] == null)
+                                       throw new UnknownToolsVersionException (value);
+                               defaultToolsVersion = value;
+                       }
                }
                
                public bool IsBuilding {
index 0bda5abba45a7853ca3dd3f0a741dce166169980..c2de8c7fc9ecb1e9ef854cae64178bd1f39a4fe4 100644 (file)
@@ -798,12 +798,13 @@ namespace Microsoft.Build.BuildEngine {
                        targets = new TargetCollection (this);
                        last_item_group_containing = new Dictionary <string, BuildItemGroup> ();
                        
+                       string effective_tools_version = GetToolsVersionToUse ();
                        taskDatabase = new TaskDatabase ();
-                       taskDatabase.CopyTasks (ParentEngine.GetDefaultTasks (GetToolsVersionToUse ()));
+                       taskDatabase.CopyTasks (ParentEngine.GetDefaultTasks (effective_tools_version));
 
                        initialTargets = new List<string> ();
                        defaultTargets = new string [0];
-                       PrepareForEvaluate ();
+                       PrepareForEvaluate (effective_tools_version);
                        ProcessElements (xmlDocument.DocumentElement, null);
                        
                        isDirty = false;
@@ -871,7 +872,7 @@ namespace Microsoft.Build.BuildEngine {
                        }
                }
                
-               void PrepareForEvaluate ()
+               void PrepareForEvaluate (string effective_tools_version)
                {
                        evaluatedItems = new BuildItemGroup (null, this, null, true);
                        evaluatedItemsIgnoringCondition = new BuildItemGroup (null, this, null, true);
@@ -880,7 +881,7 @@ namespace Microsoft.Build.BuildEngine {
                        if (building && current_settings == BuildSettings.None)
                                RemoveBuiltTargets ();
 
-                       InitializeProperties ();
+                       InitializeProperties (effective_tools_version);
                }
 
                void Evaluate ()
@@ -899,7 +900,7 @@ namespace Microsoft.Build.BuildEngine {
                                ParentEngine.BuiltTargetsOutputByName.Remove (key);
                }
 
-               void InitializeProperties ()
+               void InitializeProperties (string effective_tools_version)
                {
                        BuildProperty bp;
 
@@ -932,13 +933,12 @@ namespace Microsoft.Build.BuildEngine {
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildProjectName",
                                                Path.GetFileNameWithoutExtension (fullFileName),
                                                PropertyType.Reserved));
-                       string toolsVersionToUse = GetToolsVersionToUse ();
-                       string toolsPath = parentEngine.Toolsets [toolsVersionToUse].ToolsPath;
+                       string toolsPath = parentEngine.Toolsets [effective_tools_version].ToolsPath;
                        if (toolsPath == null)
-                               throw new Exception ("Unknown toolsVersion: " + toolsVersionToUse);
+                               throw new Exception (String.Format ("Invalid tools version '{0}', no tools path set for this.", effective_tools_version));
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildBinPath", toolsPath, PropertyType.Reserved));
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsPath", toolsPath, PropertyType.Reserved));
-                       EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsVersion", toolsVersionToUse, PropertyType.Reserved));
+                       EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsVersion", effective_tools_version, PropertyType.Reserved));
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildExtensionsPath", ExtensionsPath, PropertyType.Reserved));
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildExtensionsPath32", ExtensionsPath, PropertyType.Reserved));
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildProjectDefaultTargets", DefaultTargets, PropertyType.Reserved));
@@ -954,16 +954,25 @@ namespace Microsoft.Build.BuildEngine {
                        EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildProjectDirectory", projectDir, PropertyType.Reserved));
                }
 
+               // precedence:
+               // ToolsVersion property
+               // ToolsVersion attribute on the project
+               // parentEngine's DefaultToolsVersion
                string GetToolsVersionToUse ()
                {
-                       if (String.IsNullOrEmpty (ToolsVersion)) {
-                               if (HasToolsVersionAttribute)
-                                       return DefaultToolsVersion;
-                               else
-                                       return parentEngine.DefaultToolsVersion;
-                       } else {
+                       if (!String.IsNullOrEmpty (ToolsVersion))
                                return ToolsVersion;
+
+                       if (!HasToolsVersionAttribute)
+                               return parentEngine.DefaultToolsVersion;
+
+                       if (parentEngine.Toolsets [DefaultToolsVersion] == null) {
+                               LogWarning (FullFileName, "Project has unknown ToolsVersion '{0}'. Using the default tools version '{1}' instead.",
+                                               DefaultToolsVersion, parentEngine.DefaultToolsVersion);
+                               return parentEngine.DefaultToolsVersion;
                        }
+
+                       return DefaultToolsVersion;
                }
                
                void AddProjectExtensions (XmlElement xmlElement)
diff --git a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UnknownToolsVersionException.cs b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UnknownToolsVersionException.cs
new file mode 100644 (file)
index 0000000..fc07678
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// UnknownToolsVersionException.cs
+//
+// Author:
+//     Ankit Jain (jankit@novell.com)
+// 
+// Copyright 2010 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#if NET_2_0
+
+using System;
+using System.Runtime.Serialization;
+using System.Text;
+
+namespace Microsoft.Build.BuildEngine {
+       [Serializable]
+       internal class UnknownToolsVersionException : Exception {
+               string message;
+
+               public UnknownToolsVersionException (string toolsVersion)
+               {
+                       this.message = GetErrorMessage (toolsVersion);
+               }
+
+               public UnknownToolsVersionException (string toolsVersion, string message)
+               {
+                       this.message = String.Format ("{0}. {1}", message, GetErrorMessage (toolsVersion));
+               }
+
+               public UnknownToolsVersionException (string message,
+                                       Exception innerException)
+                       : base (message, innerException)
+               {
+               }
+
+               protected UnknownToolsVersionException (SerializationInfo info,
+                                          StreamingContext context)
+                       : base (info, context)
+               {
+               }
+
+               public override string Message {
+                       get { return message; }
+               }
+
+               string GetErrorMessage (string toolsVersion)
+               {
+                       StringBuilder sb = new StringBuilder ();
+                       sb.AppendFormat ("Unknown tools version: '{0}' . Known versions:", toolsVersion);
+
+                       foreach (var ts in Engine.GlobalEngine.Toolsets)
+                               sb.AppendFormat (" '{0}'", ts.ToolsVersion);
+
+                       return sb.ToString ();
+               }
+       }
+}
+
+#endif
index 02bc4c2002f52f7d3fc229bd9fe12e3093a34fbd..923aa2f51b03c8f5b01441448418fe491232b50e 100644 (file)
@@ -60,6 +60,7 @@ Microsoft.Build.BuildEngine/Token.cs
 Microsoft.Build.BuildEngine/Toolset.cs
 Microsoft.Build.BuildEngine/ToolsetCollection.cs
 Microsoft.Build.BuildEngine/ToolsetDefinitionLocations.cs
+Microsoft.Build.BuildEngine/UnknownToolsVersionException.cs
 Microsoft.Build.BuildEngine/UsingTask.cs
 Microsoft.Build.BuildEngine/UsingTaskCollection.cs
 Microsoft.Build.BuildEngine/Utilities.cs
index ff531ad0138f6193cc204abd49f2c52747e33b05..a1d7d3e4ad0efd2460e44c495edace502896405f 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-09  Ankit Jain  <jankit@novell.com>
+
+       * Microsoft.Build.Tasks.dll.sources: Use
+       UnknownToolsVersionException.cs from Engine.
+
 2010-04-03  Ankit Jain  <jankit@novell.com>
 
        * Makefile: Import tools/xbuild/xbuild_targets.make, which copies
index 9b6d2160248d8586f14672298060d8f25af6571b..9d53168e61fb039f529ff74396fb7d505e2ce381 100644 (file)
@@ -114,3 +114,4 @@ Mono.XBuild.Tasks.GenerateResourceInternal/PoResourceWriter.cs
 Mono.XBuild.Tasks.GenerateResourceInternal/TxtResourceReader.cs
 Mono.XBuild.Tasks.GenerateResourceInternal/TxtResourceWriter.cs
 ../Microsoft.Build.Engine/Microsoft.Build.BuildEngine/DirectoryScanner.cs
+../Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UnknownToolsVersionException.cs
index 90c54cd38c5cb987ae6302701db1ecee5835df44..6409867cca34ff94da90944690a1643a4378c4a1 100644 (file)
@@ -88,11 +88,14 @@ namespace Microsoft.Build.Tasks {
 
                                try {
                                        // Order of precedence:
-                                       // %(Project.ToolsVersion) , ToolsVersion property
-                                       string tv = project.GetMetadata ("ToolsVersion");
+                                       // ToolsVersion property, %(Project.ToolsVersion)
+                                       string tv = ToolsVersion;
                                        if (String.IsNullOrEmpty (tv))
-                                               tv = ToolsVersion;
-                                       ThrowIfNotValidToolsVersion (tv);
+                                               // metadata on the Project item
+                                               tv = project.GetMetadata ("ToolsVersion");
+
+                                       if (!String.IsNullOrEmpty (tv) && Engine.GlobalEngine.Toolsets [tv] == null)
+                                               throw new UnknownToolsVersionException (tv);
 
                                        result = BuildEngine2.BuildProjectFile (filename, targets, global_properties, outputs, tv);
                                } catch (InvalidProjectFileException e) {
@@ -139,10 +142,10 @@ namespace Microsoft.Build.Tasks {
                        return result;
                }
 
-               void ThrowIfNotValidToolsVersion (string toolsVersion)
+               void ThrowIfInvalidToolsVersion (string toolsVersion)
                {
                        if (!String.IsNullOrEmpty (toolsVersion) && Engine.GlobalEngine.Toolsets [toolsVersion] == null)
-                               throw new Exception (String.Format ("Unknown ToolsVersion : {0}", toolsVersion));
+                               throw new UnknownToolsVersionException (toolsVersion);
                }
 
                [Required]
index 73c326e93e68b00ba82f2db19ee264372f747187..a68f2d5788335f7c69accc34e714e2beb45c0a93 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-09  Ankit Jain  <jankit@novell.com>
+
+       * MessageTest (TestExecution): Additional messages with 'low'
+       importance get emitted, so don't expect sequential messages.
+
 2010-04-06  Ankit Jain  <jankit@novell.com>
 
        * Consts.cs: Remove.
index 1b9cec89eb0f22e04e990db45c1868c7d9cc6c3b..22d6d636267d17b523df7613fa246c5192d6160e 100644 (file)
@@ -72,14 +72,14 @@ namespace MonoTests.Microsoft.Build.Tasks {
                        string documentString = @"
                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                                        <Target Name='1'>
-                                               <Message Text='Text' Importance='Low'/>
-                                               <Message Text='Text' Importance='Normal'/>
-                                               <Message Text='Text' Importance='High'/>
-                                               <Message Text='Text' Importance='low'/>
-                                               <Message Text='Text' Importance='normal'/>
-                                               <Message Text='Text' Importance='high'/>
-                                               <Message Text='Text' />
-                                               <Message Text='Text' Importance='weird_importance'/>
+                                               <Message Text='Text1' Importance='Low'/>
+                                               <Message Text='Text2' Importance='Normal'/>
+                                               <Message Text='Text3' Importance='High'/>
+                                               <Message Text='Text4' Importance='low'/>
+                                               <Message Text='Text5' Importance='normal'/>
+                                               <Message Text='Text6' Importance='high'/>
+                                               <Message Text='Text7' />
+                                               <Message Text='Text8' Importance='weird_importance'/>
                                        </Target>
                                </Project>
                        ";
@@ -90,16 +90,20 @@ namespace MonoTests.Microsoft.Build.Tasks {
                        
                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);
-                       project.Build ("1");
+                       if (project.Build ("1")) {
+                               testLogger.DumpMessages ();
+                               Assert.Fail ("Build should have failed");
+                       }
                        
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.Low), "A1");
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.Normal), "A2");
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.High), "A3");
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.Low), "A4");
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.Normal), "A5");
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.High), "A6");
-                       Assert.AreEqual (0, testLogger.CheckHead ("Text", MessageImportance.Normal), "A7");
-                       Assert.AreEqual (1, testLogger.CheckHead ("Text", MessageImportance.Normal), "A8");
+                       testLogger.DumpMessages ();
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text1", MessageImportance.Low), "A1");
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text2", MessageImportance.Normal), "A2");
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text3", MessageImportance.High), "A3");
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text4", MessageImportance.Low), "A4");
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text5", MessageImportance.Normal), "A5");
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text6", MessageImportance.High), "A6");
+                       Assert.AreEqual (0, testLogger.CheckAny ("Text7", MessageImportance.Normal), "A7");
+                       Assert.AreEqual (1, testLogger.CheckAny ("Text8", MessageImportance.Normal), "A8");
                        
                }
        }
index fadac368ad266c5132ae95c0b3641aeccdec913c..6ee647c2b3f13c5a151887019662f2be9b100857 100644 (file)
@@ -1,3 +1,10 @@
+2010-07-09  Ankit Jain  <jankit@novell.com>
+
+       * Main.cs: Use tools version specified on the command line, if
+       any.
+       * xbuild.exe.sources: Include UnknownToolsVersionException.cs from
+       MS.B.Engine
+
 2010-06-23  Ankit Jain  <jankit@novell.com>
 
        * xbuild/Microsoft.CSharp.targets (CoreCompile): Fix inputs.
index 89c84632a8d3737dc9e6513211a52fdc6bef7125..88fc1b7f49329daaae045c0bac7f33b79f340890 100644 (file)
@@ -34,6 +34,7 @@ using System;
 using System.Collections;
 using System.IO;
 using System.Reflection;
+using System.Text;
 using Microsoft.Build.BuildEngine;
 using Microsoft.Build.Framework;
 using Microsoft.Build.Utilities;
@@ -78,11 +79,10 @@ namespace Mono.XBuild.CommandLine {
                                if (parameters.DisplayVersion)
                                        ErrorUtilities.ShowVersion (false);
                                
-                               //FIXME: cmd line arg to set toolsversion
                                engine  = Engine.GlobalEngine;
                                if (!String.IsNullOrEmpty (parameters.ToolsVersion)) {
                                        if (engine.Toolsets [parameters.ToolsVersion] == null)
-                                               ErrorUtilities.ReportError (0, String.Format ("Unknown tools version : {0}", parameters.ToolsVersion));
+                                               ErrorUtilities.ReportError (0, new UnknownToolsVersionException (parameters.ToolsVersion).Message);
 
                                        engine.DefaultToolsVersion = parameters.ToolsVersion;
                                }
@@ -125,14 +125,7 @@ namespace Mono.XBuild.CommandLine {
                                        return;
                                }
 
-                               project.Load (projectFile);
-                               
-                               string oldCurrentDirectory = Environment.CurrentDirectory;
-                               string dir = Path.GetDirectoryName (projectFile);
-                               if (!String.IsNullOrEmpty (dir))
-                                       Directory.SetCurrentDirectory (dir);
-                               result = engine.BuildProject (project, parameters.Targets, null);
-                               Directory.SetCurrentDirectory (oldCurrentDirectory);
+                               result = engine.BuildProjectFile (projectFile, parameters.Targets, null, null, BuildSettings.None, parameters.ToolsVersion);
                        }
                        
                        catch (InvalidProjectFileException ipfe) {
@@ -159,7 +152,6 @@ namespace Mono.XBuild.CommandLine {
                        }
 
                }
-
        }
 
        // code from mcs/report.cs
index f1544f7ab1ae88e0716917276fad392b998d9f02..bfb39197517bdfec07172c167f7085fa7fa8dcaf 100644 (file)
@@ -1,4 +1,5 @@
 ../../build/common/Consts.cs
+../../class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UnknownToolsVersionException.cs
 ../../class/Microsoft.Build.Framework/Mono.XBuild.Framework/AssemblyLoadInfo.cs
 AssemblyInfo.cs
 CommandLineException.cs