diff --git a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs index 9d0a5404cb..4c1e4b6fcb 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs @@ -112,7 +112,7 @@ namespace ICSharpCode.SharpDevelop.Project protected virtual void Create(ProjectCreateInformation information) { - InitializeMSBuildProject(); + InitializeMSBuildProject(project); Name = information.ProjectName; FileName = information.OutputProjectFileName; @@ -788,7 +788,7 @@ namespace ICSharpCode.SharpDevelop.Project #region Loading protected bool isLoading; - void InitializeMSBuildProject() + internal static void InitializeMSBuildProject(MSBuild.Project project) { project.GlobalProperties.SetProperty("BuildingInsideVisualStudio", "true"); foreach (KeyValuePair pair in MSBuildEngine.MSBuildProperties) { @@ -802,7 +802,7 @@ namespace ICSharpCode.SharpDevelop.Project try { this.FileName = fileName; - InitializeMSBuildProject(); + InitializeMSBuildProject(project); try { project.Load(fileName); diff --git a/src/Main/Base/Project/Src/Project/MSBuildInternals.cs b/src/Main/Base/Project/Src/Project/MSBuildInternals.cs index 1c4bcf08f5..72775f2a92 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildInternals.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildInternals.cs @@ -119,11 +119,17 @@ namespace ICSharpCode.SharpDevelop.Project if (tempProject != null && tempProject != baseProject) { tempProject.ParentEngine.UnloadAllProjects(); } - MSBuild.Engine engine = CreateEngine(); - tempProject = engine.CreateNewProject(); - tempProject.LoadXml(baseProject.Xml); - tempProject.SetProperty("Configuration", configuration); - tempProject.SetProperty("Platform", platform); + try { + MSBuild.Engine engine = CreateEngine(); + tempProject = engine.CreateNewProject(); + MSBuildBasedProject.InitializeMSBuildProject(tempProject); + tempProject.LoadXml(baseProject.Xml); + tempProject.SetProperty("Configuration", configuration); + tempProject.SetProperty("Platform", platform); + } catch (Exception ex) { + ICSharpCode.Core.MessageService.ShowWarning(ex.ToString()); + tempProject = baseProject; + } } internal static PropertyStorageLocations GetLocationFromCondition(string condition) diff --git a/src/Main/Core/Project/Src/Services/MessageService/MessageService.cs b/src/Main/Core/Project/Src/Services/MessageService/MessageService.cs index 1ce9bd62e4..1b95e77aa4 100644 --- a/src/Main/Core/Project/Src/Services/MessageService/MessageService.cs +++ b/src/Main/Core/Project/Src/Services/MessageService/MessageService.cs @@ -81,20 +81,17 @@ namespace ICSharpCode.Core } if (MessageService.MainForm == null) { - // let's try this; don't know if it's threadsafe? I expect - // that MainForm.InvokeRequired can be assumed to be false - // if MainForm doesn't exist yet... - MessageBox.Show(StringParser.Parse(msg), StringParser.Parse("SharpDevelop: ${res:Global.ErrorText}"), MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(StringParser.Parse(msg), StringParser.Parse("SharpDevelop: ${res:Global.ErrorText}"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { - - MethodInvoker showError = delegate { - MessageBox.Show(MessageService.MainForm, StringParser.Parse(msg), StringParser.Parse("${res:Global.ErrorText}"), MessageBoxButtons.OK, MessageBoxIcon.Error); - }; - if (MessageService.MainForm.InvokeRequired) { - MessageService.MainForm.BeginInvoke(showError);; - } else { - showError(); - } + + MethodInvoker showError = delegate { + MessageBox.Show(MessageService.MainForm, StringParser.Parse(msg), StringParser.Parse("${res:Global.ErrorText}"), MessageBoxButtons.OK, MessageBoxIcon.Error); + }; + if (MessageService.MainForm.InvokeRequired) { + MessageService.MainForm.BeginInvoke(showError); + } else { + showError(); + } } } @@ -102,13 +99,25 @@ namespace ICSharpCode.Core { message = StringParser.Parse(message); LoggingService.Warn(message); - MessageBox.Show(MessageService.MainForm, - message, - StringParser.Parse("${res:Global.WarningText}"), - MessageBoxButtons.OK, - MessageBoxIcon.Warning, - MessageBoxDefaultButton.Button1, - GetOptions(message, message)); + + string caption = StringParser.Parse("${res:Global.WarningText}"); + if (MessageService.MainForm == null) { + MessageBox.Show(message, caption, + MessageBoxButtons.OK, MessageBoxIcon.Warning, + MessageBoxDefaultButton.Button1, GetOptions(message, caption)); + } else { + MethodInvoker showWarning = delegate { + MessageBox.Show(MessageService.MainForm, + message, caption, + MessageBoxButtons.OK, MessageBoxIcon.Warning, + MessageBoxDefaultButton.Button1, GetOptions(message, caption)); + }; + if (MessageService.MainForm.InvokeRequired) { + MessageService.MainForm.BeginInvoke(showWarning); + } else { + showWarning(); + } + } } public static void ShowWarningFormatted(string formatstring, params string[] formatitems)