[mono/monodevelop] dbd1c0e5: [Project] Only default to MSBuild engine if referenced projects use it

"Michael Hutchinson ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141d2af763d-6ff6467a-64b4-408a-b1ad-8b7c1401b5cb-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/705b277ee93c...dbd1c0e5959a

   Commit: dbd1c0e5959a2e590aefa16357c85f5514f56e6e
   Author: Michael Hutchinson <[email protected]> (mhutch)
     Date: 2013-10-19 21:40:13 GMT
      URL: https://github.com/mono/monodevelop/commit/dbd1c0e5959a2e590aefa16357c85f5514f56e6e

[Project] Only default to MSBuild engine if referenced projects use it

MSBuild fails to handle project references if those projects cannot be
built with MSBuild.

Changed paths:
  M main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs
  M main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs
  M main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs

Modified: main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs
===================================================================
@@ -154,10 +154,8 @@ public virtual void InitializeHandler (SolutionEntityItem item)
 			MSBuildProjectHandler h = (MSBuildProjectHandler) ProjectExtensionUtil.GetItemHandler (item);
 			UpdateImports (item, h.TargetImports);
 			h.SubtypeGuids.Add (guid);
-			if (UseXBuild)
-				h.UseMSBuildEngineByDefault = true;
-			if (RequireXBuild)
-				h.RequireMSBuildEngine = true;
+			h.UseMSBuildEngineByDefault |= UseXBuild;
+			h.RequireMSBuildEngine |= RequireXBuild;
 		}
 		
 		public void UpdateImports (SolutionEntityItem item, List<string> imports)

Modified: main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs
===================================================================
@@ -195,7 +195,7 @@ ProjectConfigurationInfo[] GetConfigurations (SolutionEntityItem item, Configura
 		
 		IEnumerable<string> IAssemblyReferenceHandler.GetAssemblyReferences (ConfigurationSelector configuration)
 		{
-			if (UseMSBuildEngineForItem (Item)) {
+			if (UseMSBuildEngineForItem (Item, configuration)) {
 				// Get the references list from the msbuild project
 				SolutionEntityItem item = (SolutionEntityItem) Item;
 				RemoteProjectBuilder builder = GetProjectBuilder ();
@@ -217,7 +217,7 @@ IEnumerable<string> IAssemblyReferenceHandler.GetAssemblyReferences (Configurati
 		
 		public override BuildResult RunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration)
 		{
-			if (UseMSBuildEngineForItem (Item)) {
+			if (UseMSBuildEngineForItem (Item, configuration)) {
 				SolutionEntityItem item = Item as SolutionEntityItem;
 				if (item != null) {
 					
@@ -342,9 +342,26 @@ public SolutionEntityItem Load (IProgressMonitor monitor, string fileName, MSBui
 		}
 
 		/// <summary>Whether to use the MSBuild engine for the specified item.</summary>
-		internal bool UseMSBuildEngineForItem (SolutionItem item)
+		internal bool UseMSBuildEngineForItem (SolutionItem item, ConfigurationSelector sel, bool checkReferences = true)
 		{
-			return item.UseMSBuildEngine ?? UseMSBuildEngineByDefault;
+			// if the item mandates MSBuild, always use it
+			if (RequireMSBuildEngine)
+				return true;
+			// if the user has set the option, use the setting
+			if (item.UseMSBuildEngine.HasValue)
+				return item.UseMSBuildEngine.Value;
+
+			// If the item type defaults to using MSBuild, only use MSBuild if its direct references also use MSBuild.
+			// This prevents a not-uncommon common error referencing non-MSBuild projects from MSBuild projects
+			// NOTE: This adds about 11ms to the load/build/etc times of the MonoDevelop solution. Doing it recursively
+			// adds well over a second.
+			return UseMSBuildEngineByDefault && (
+				!checkReferences ||
+				item.GetReferencedItems (sel).All (i => {
+					var h = i.ItemHandler as MSBuildProjectHandler;
+					return h != null && h.UseMSBuildEngineForItem (i, sel, false);
+				})
+			);
 		}
 
 		/// <summary>Whether to use the MSBuild engine by default.</summary>

Modified: main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs
===================================================================
@@ -405,10 +405,10 @@ public ProjectFile AddDirectory (string relativePath)
 		
 		//HACK: the build code is structured such that support file copying is in here instead of the item handler
 		//so in order to avoid doing them twice when using the msbuild engine, we special-case them
-		bool UsingMSBuildEngine ()
+		bool UsingMSBuildEngine (ConfigurationSelector sel)
 		{
 			var msbuildHandler = ItemHandler as MonoDevelop.Projects.Formats.MSBuild.MSBuildProjectHandler;
-			return msbuildHandler != null && msbuildHandler.UseMSBuildEngineForItem (this);
+			return msbuildHandler != null && msbuildHandler.UseMSBuildEngineForItem (this, sel);
 		}
 
 		protected override BuildResult OnBuild (IProgressMonitor monitor, ConfigurationSelector configuration)
@@ -423,7 +423,7 @@ protected override BuildResult OnBuild (IProgressMonitor monitor, ConfigurationS
 			
 			StringParserService.Properties["Project"] = Name;
 			
-			if (UsingMSBuildEngine ()) {
+			if (UsingMSBuildEngine (configuration)) {
 				return DoBuild (monitor, configuration);
 			}
 			
@@ -649,7 +649,7 @@ protected override void OnClean (IProgressMonitor monitor, ConfigurationSelector
 				return;
 			}
 			
-			if (UsingMSBuildEngine ()) {
+			if (UsingMSBuildEngine (configuration)) {
 				DoClean (monitor, config.Selector);
 				return;
 			}


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.