Browse Source

Fixed NullReferenceException in MSBuildBasedProject.get_MinimumSolutionVersion() when removing a project from the solution while the build is running. (http://community.sharpdevelop.net/forums/t/12316.aspx)

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
238c0a2391
  1. 14
      src/Main/Base/Project/Src/Project/BuildEngine.cs
  2. 5
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

14
src/Main/Base/Project/Src/Project/BuildEngine.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
@ -274,7 +275,15 @@ namespace ICSharpCode.SharpDevelop.Project @@ -274,7 +275,15 @@ namespace ICSharpCode.SharpDevelop.Project
public void DoStartBuild(object state)
{
project.StartBuild(options, this);
string name = string.Empty;
try {
name = project.Name;
project.StartBuild(options, this);
} catch (ObjectDisposedException) {
// Handle ObjectDisposedException that occurs when trying to build a project that was unloaded.
ReportError(new BuildError(null, "The project '" + name + "' was unloaded."));
Done(false);
}
}
public void ReportError(BuildError error)
@ -630,6 +639,9 @@ namespace ICSharpCode.SharpDevelop.Project @@ -630,6 +639,9 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
if (messagesToReport != null) {
// we can report these messages outside the lock:
// while they swap order with messages currently coming in (ReportMessage),
// this shouldn't be a problem as nodes should not report messages after they finish building.
messagesToReport.ForEach(ReportMessageInternal);
}
if (newNodeWithOutputLockAlreadyFinishedBuilding) {

5
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -98,6 +98,11 @@ namespace ICSharpCode.SharpDevelop.Project @@ -98,6 +98,11 @@ namespace ICSharpCode.SharpDevelop.Project
public override int MinimumSolutionVersion {
get {
lock (SyncRoot) {
// This property is called by CSharpProject.StartBuild (and other derived StartBuild methods),
// so it's important that we throw an ObjectDisposedException for disposed projects.
// The build engine will handle this exception (occurs when unloading a project while a build is running)
if (projectFile == null)
throw new ObjectDisposedException("MSBuildBasedProject");
if (string.IsNullOrEmpty(projectFile.ToolsVersion) || projectFile.ToolsVersion == "2.0") {
return Solution.SolutionVersionVS2005;
} else if (projectFile.ToolsVersion == "3.0" || projectFile.ToolsVersion == "3.5") {

Loading…
Cancel
Save