Browse Source

Fixed support for parallel builds.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/dotnet4@4288 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
528f42af4f
  1. 2
      debugbuild.bat
  2. 51
      src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs

2
debugbuild.bat

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
%windir%\microsoft.net\framework\v4.0.20506\msbuild SharpDevelop.sln /p:Configuration=Debug "/p:FSharpBuildTasksPath=%CD%\src\AddIns\BackendBindings\FSharp\RequiredLibraries" "/p:Platform=Any CPU"
%windir%\microsoft.net\framework\v4.0.20506\msbuild /m SharpDevelop.sln /p:Configuration=Debug "/p:FSharpBuildTasksPath=%CD%\src\AddIns\BackendBindings\FSharp\RequiredLibraries" "/p:Platform=Any CPU"
@IF %ERRORLEVEL% NEQ 0 GOTO err
rem %windir%\microsoft.net\framework\v4.0.20506\msbuild /m AddIns\Misc\Profiler\AutomatedBuild.proj /p:Configuration=Debug
@IF %ERRORLEVEL% NEQ 0 GOTO err

51
src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs

@ -148,6 +148,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -148,6 +148,7 @@ namespace ICSharpCode.SharpDevelop.Project
public bool ReportUnknownEvents { get; set; }
List<string> interestingTasks = new List<string>();
string temporaryFileName;
/// <summary>
/// The list of task names for which TaskStarted and TaskFinished events should be
@ -194,29 +195,39 @@ namespace ICSharpCode.SharpDevelop.Project @@ -194,29 +195,39 @@ namespace ICSharpCode.SharpDevelop.Project
return new ParallelMSBuildManager(new MSBuild.ProjectCollection());
});
// Use a temporary project collection to prevent MSBuild from opening the element from the global collection
// - we don't want to modify the ProjectRootElement opened as project because we don't want to save
// back our changes to disk.
ProjectRootElement projectFile = ProjectRootElement.Open(project.FileName, manager.ProjectCollection);
foreach (string import in additionalTargetFiles)
projectFile.AddImport(import);
if (globalProperties.ContainsKey("BuildingInsideVisualStudio")) {
// When we set BuildingInsideVisualStudio, MSBuild skips its own change detection
// because in Visual Studio, the host compiler does the change detection.
// We override the property '_ComputeNonExistentFileProperty' which is responsible
// for recompiling each time - our _ComputeNonExistentFileProperty does nothing,
// which re-enables the MSBuild's usual change detection.
projectFile.AddTarget("_ComputeNonExistentFileProperty");
// Using projects with in-memory modifications doesn't work with parallel build.
// As a work-around, we'll write our modifications to a file and force MSBuild to include that file using a custom property.
temporaryFileName = Path.GetTempFileName();
using (StreamWriter w = new StreamWriter(temporaryFileName)) {
w.WriteLine("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
foreach (string import in additionalTargetFiles) {
w.WriteLine(" <Import Project=\"" + import + "\" />");
}
if (globalProperties.ContainsKey("BuildingInsideVisualStudio")) {
// When we set BuildingInsideVisualStudio, MSBuild skips its own change detection
// because in Visual Studio, the host compiler does the change detection.
// We override the target '_ComputeNonExistentFileProperty' which is responsible
// for recompiling each time - our _ComputeNonExistentFileProperty does nothing,
// which re-enables the MSBuild's usual change detection.
w.WriteLine(" <Target Name=\"_ComputeNonExistentFileProperty\" />");
}
w.WriteLine("</Project>");
// inject our imports at the end of 'Microsoft.Common.Targets' by replacing the CodeAnalysisTargets.
if (globalProperties.ContainsKey("CodeAnalysisTargets")) {
w.WriteLine(" <Import Project=\"" + globalProperties["CodeAnalysisTargets"] + "\" />");
}
globalProperties["CodeAnalysisTargets"] = temporaryFileName;
}
ProjectInstance projectInstance = MSBuildInternals.LoadProjectInstance(manager.ProjectCollection, projectFile, globalProperties);
string fileName = project.FileName;
string[] targets = { options.Target.TargetName };
BuildRequestData requestData = new BuildRequestData(projectInstance, targets, new HostServices());
BuildRequestData requestData = new BuildRequestData(fileName, globalProperties, null, targets, new HostServices());
ILogger[] loggers = {
new SharpDevelopLogger(this),
new BuildLogFileLogger(projectFile.FullPath + ".log", LoggerVerbosity.Diagnostic)
new BuildLogFileLogger(fileName + ".log", LoggerVerbosity.Diagnostic)
};
manager.StartBuild(requestData, loggers, OnComplete);
}
@ -454,6 +465,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -454,6 +465,10 @@ namespace ICSharpCode.SharpDevelop.Project
public void Shutdown()
{
if (worker.temporaryFileName != null) {
File.Delete(worker.temporaryFileName);
worker.temporaryFileName = null;
}
}
#endregion
}

Loading…
Cancel
Save