diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2013-08-28 22:30:02 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@xamarin.com> | 2013-08-28 22:30:28 +0400 |
commit | acdd9843e2ab916b8f84bbf4f12f78d9f1f60386 (patch) | |
tree | 3ee2f145acc46f1ee14deb89bbca233a8d20a4a2 /main/src/core/MonoDevelop.Projects.Formats.MSBuild | |
parent | 1e2a5fe6d8f2d5de1c273eed3183dfd9bfefd528 (diff) |
Better workaround for xbuild bug #14295
Diffstat (limited to 'main/src/core/MonoDevelop.Projects.Formats.MSBuild')
2 files changed, 26 insertions, 14 deletions
diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs index c04a510c22..6644ad3f79 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs @@ -105,14 +105,6 @@ namespace MonoDevelop.Projects.Formats.MSBuild }); } - internal void ClearUnsavedProjectContent () - { - lock (unsavedProjects) { - foreach (var f in new List<string> (unsavedProjects.Keys)) - UnloadProject (f); - } - } - internal void SetUnsavedProjectContent (string file, string content) { lock (unsavedProjects) diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs index 0e49ef8fa5..5690bd9c67 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs @@ -33,6 +33,7 @@ using Microsoft.Build.BuildEngine; using Microsoft.Build.Framework; using System.Collections.Generic; using System.Collections; +using System.Reflection; namespace MonoDevelop.Projects.Formats.MSBuild { @@ -78,9 +79,6 @@ namespace MonoDevelop.Projects.Formats.MSBuild public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity) { - // Unload all unsaved projects. We build from what's saved in disk. - buildEngine.ClearUnsavedProjectContent (); -
MSBuildResult[] result = null;
BuildEngine.RunSTA (delegate
{
@@ -157,9 +155,18 @@ namespace MonoDevelop.Projects.Formats.MSBuild var content = buildEngine.GetUnsavedProjectContent (pc.ProjectFile);
if (content == null)
p.Load (pc.ProjectFile);
- else {
- p.FullFileName = pc.ProjectFile;
- p.Load (new StringReader (content));
+ else { + p.FullFileName = pc.ProjectFile; + + if (HasXbuildFileBug ()) { + // Workaround for Xamarin bug #14295: Project.Load incorrectly resets the FullFileName property + var t = p.GetType (); + t.InvokeMember ("project_load_settings", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, p, new object[] { ProjectLoadSettings.None }); + t.InvokeMember ("PushThisFileProperty", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, p, new object[] { p.FullFileName });
+ t.InvokeMember ("DoLoad", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, p, new object[] { new StringReader (content) }); + } else { + p.Load (new StringReader (content)); + } } } p.GlobalProperties.SetProperty ("Configuration", pc.Configuration); @@ -174,6 +181,19 @@ namespace MonoDevelop.Projects.Formats.MSBuild Environment.CurrentDirectory = Path.GetDirectoryName (file); return project; } + + bool? hasXbuildFileBug; + + bool HasXbuildFileBug () + { + if (hasXbuildFileBug == null) { + Project p = new Project (); + p.FullFileName = "foo"; + p.LoadXml ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"/>"); + hasXbuildFileBug = p.FullFileName.Length == 0; + } + return hasXbuildFileBug.Value; + } public override object InitializeLifetimeService () { |