[xbuild] Warn for unknown toolsVersion only on build.
authorAnkit Jain <radical@corewars.org>
Wed, 2 Feb 2011 12:19:05 +0000 (17:49 +0530)
committerAnkit Jain <radical@corewars.org>
Wed, 2 Feb 2011 12:40:33 +0000 (18:10 +0530)
Emit warning for unknown toolsversion only on a build, and
*not* everytime the project file is parsed.

* class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
(GetToolsVersionToUse): Add a 'emitWarning' bool param.
(Build): Call GetToolsVersionToUse () to ensure that a warning is
emitted in case of a unknown tools version.

mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs

index fdb3d250fd7ba92f212bd18149ca6a2747f39c27..d8f0a92061f122bff013b68ace698981a5f09306 100644 (file)
@@ -277,6 +277,11 @@ namespace Microsoft.Build.BuildEngine {
                {
                        bool result = false;
                        ParentEngine.StartProjectBuild (this, targetNames);
+
+                       // Invoking this to emit a warning in case of unsupported
+                       // ToolsVersion
+                       GetToolsVersionToUse (true);
+
                        string current_directory = Environment.CurrentDirectory;
                        try {
                                current_settings = buildFlags;
@@ -811,7 +816,7 @@ namespace Microsoft.Build.BuildEngine {
                        targets = new TargetCollection (this);
                        last_item_group_containing = new Dictionary <string, BuildItemGroup> ();
                        
-                       string effective_tools_version = GetToolsVersionToUse ();
+                       string effective_tools_version = GetToolsVersionToUse (false);
                        taskDatabase = new TaskDatabase ();
                        taskDatabase.CopyTasks (ParentEngine.GetDefaultTasks (effective_tools_version));
 
@@ -976,7 +981,7 @@ namespace Microsoft.Build.BuildEngine {
                // ToolsVersion property
                // ToolsVersion attribute on the project
                // parentEngine's DefaultToolsVersion
-               string GetToolsVersionToUse ()
+               string GetToolsVersionToUse (bool emitWarning)
                {
                        if (!String.IsNullOrEmpty (ToolsVersion))
                                return ToolsVersion;
@@ -985,7 +990,8 @@ namespace Microsoft.Build.BuildEngine {
                                return parentEngine.DefaultToolsVersion;
 
                        if (parentEngine.Toolsets [DefaultToolsVersion] == null) {
-                               LogWarning (FullFileName, "Project has unknown ToolsVersion '{0}'. Using the default tools version '{1}' instead.",
+                               if (emitWarning)
+                                       LogWarning (FullFileName, "Project has unknown ToolsVersion '{0}'. Using the default tools version '{1}' instead.",
                                                DefaultToolsVersion, parentEngine.DefaultToolsVersion);
                                return parentEngine.DefaultToolsVersion;
                        }