Browse Source

Fixed issue when building solution that had a mix of difference project configurations.

This bug could cause solutions to fail to build in SharpDevelop with an "OutputPath property not set" error message even though they build fine in MSBuild/VS.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5505 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head 3.2-RC1
Daniel Grunwald 16 years ago
parent
commit
23171fe112
  1. 29
      src/Main/Base/Project/Src/Project/IProject.cs
  2. 4
      src/Main/Base/Project/Src/Project/MSBuildEngine.cs
  3. 25
      src/Main/Base/Project/Src/Project/MSBuildInternals.cs
  4. 12
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  5. 2
      src/Main/ICSharpCode.SharpDevelop.BuildWorker/Program.cs

29
src/Main/Base/Project/Src/Project/IProject.cs

@ -7,8 +7,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Xml;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -301,13 +303,25 @@ namespace ICSharpCode.SharpDevelop.Project
// start of default implementation // start of default implementation
var configMatchings = buildable.ParentSolution.GetActiveConfigurationsAndPlatformsForProjects(options.SolutionConfiguration, options.SolutionPlatform); var configMatchings = buildable.ParentSolution.GetActiveConfigurationsAndPlatformsForProjects(options.SolutionConfiguration, options.SolutionPlatform);
ProjectBuildOptions projectOptions = new ProjectBuildOptions(isRootBuildable ? options.ProjectTarget : options.TargetForDependencies); ProjectBuildOptions projectOptions = new ProjectBuildOptions(isRootBuildable ? options.ProjectTarget : options.TargetForDependencies);
// find the project configuration // Find the project configuration, and build an XML string containing all configurations from the solution
foreach (var matching in configMatchings) { StringWriter solutionConfigurationXml = new StringWriter();
if (matching.Project == buildable) { using (XmlTextWriter solutionConfigurationWriter = new XmlTextWriter(solutionConfigurationXml)) {
projectOptions.Configuration = matching.Configuration; solutionConfigurationWriter.WriteStartElement("SolutionConfiguration", "");
projectOptions.Platform = matching.Platform; foreach (var matching in configMatchings) {
if (matching.Project == buildable) {
projectOptions.Configuration = matching.Configuration;
projectOptions.Platform = matching.Platform;
}
solutionConfigurationWriter.WriteStartElement("ProjectConfiguration");
solutionConfigurationWriter.WriteAttributeString("Project", matching.Project.IdGuid);
solutionConfigurationWriter.WriteValue(matching.Configuration + "|" + MSBuildInternals.FixPlatformNameForProject(matching.Platform));
solutionConfigurationWriter.WriteEndElement();
} }
solutionConfigurationWriter.WriteEndElement();
} }
// fall back to solution config if we don't find any entries for the project
if (string.IsNullOrEmpty(projectOptions.Configuration)) if (string.IsNullOrEmpty(projectOptions.Configuration))
projectOptions.Configuration = options.SolutionConfiguration; projectOptions.Configuration = options.SolutionConfiguration;
if (string.IsNullOrEmpty(projectOptions.Platform)) if (string.IsNullOrEmpty(projectOptions.Platform))
@ -320,6 +334,9 @@ namespace ICSharpCode.SharpDevelop.Project
projectOptions.Properties[pair.Key] = pair.Value; projectOptions.Properties[pair.Key] = pair.Value;
} }
} }
// Set property for solution configuration. This allows MSBuild to know the correct configuration for project references,
// which is necessary to resolve the referenced project's OutputPath.
projectOptions.Properties["CurrentSolutionConfigurationContents"] = solutionConfigurationXml.ToString();
return projectOptions; return projectOptions;
} }
} }

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

@ -73,7 +73,9 @@ namespace ICSharpCode.SharpDevelop.Project
MSBuildProperties = new SortedList<string, string>(); MSBuildProperties = new SortedList<string, string>();
MSBuildProperties.Add("SharpDevelopBinPath", Path.GetDirectoryName(typeof(MSBuildEngine).Assembly.Location)); MSBuildProperties.Add("SharpDevelopBinPath", Path.GetDirectoryName(typeof(MSBuildEngine).Assembly.Location));
MSBuildProperties.Add("BuildingInsideVisualStudio", "true"); // we always need this (even when compiling a single project) to prevent MSBuild from automatically
// building referenced projects
MSBuildProperties.Add("BuildingSolutionFile", "true");
} }

25
src/Main/Base/Project/Src/Project/MSBuildInternals.cs

@ -76,6 +76,31 @@ namespace ICSharpCode.SharpDevelop.Project
} }
#endregion #endregion
/// <summary>
/// This is a special case in MSBuild we need to take care of.
/// </summary>
public static string FixPlatformNameForProject(string platformName)
{
if (platformName == "Any CPU") {
return "AnyCPU";
} else {
return platformName;
}
}
/// <summary>
/// This is a special case in MSBuild we need to take care of.
/// Opposite of FixPlatformNameForProject
/// </summary>
public static string FixPlatformNameForSolution(string platformName)
{
if (platformName == "AnyCPU") {
return "Any CPU";
} else {
return platformName;
}
}
internal static void AddItemToGroup(MSBuild.BuildItemGroup group, ProjectItem item) internal static void AddItemToGroup(MSBuild.BuildItemGroup group, ProjectItem item)
{ {
if (group == null) if (group == null)

12
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -795,11 +795,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
static string FixPlatformNameForProject(string platformName) static string FixPlatformNameForProject(string platformName)
{ {
if (platformName == "Any CPU") { return MSBuildInternals.FixPlatformNameForProject(platformName);
return "AnyCPU";
} else {
return platformName;
}
} }
/// <summary> /// <summary>
@ -808,11 +804,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
static string FixPlatformNameForSolution(string platformName) static string FixPlatformNameForSolution(string platformName)
{ {
if (platformName == "AnyCPU") { return MSBuildInternals.FixPlatformNameForSolution(platformName);
return "Any CPU";
} else {
return platformName;
}
} }
internal class ProjectConfigurationPlatformMatching internal class ProjectConfigurationPlatformMatching

2
src/Main/ICSharpCode.SharpDevelop.BuildWorker/Program.cs

@ -251,12 +251,14 @@ namespace ICSharpCode.SharpDevelop.BuildWorker
try { try {
project.Load(fileName); project.Load(fileName);
/* No longer necessary as we stopped using BuildingInsideVisualStudio
// When we set BuildingInsideVisualStudio, MSBuild tries to build all projects // When we set BuildingInsideVisualStudio, MSBuild tries to build all projects
// every time because in Visual Studio, the host compiler does the change detection // every time because in Visual Studio, the host compiler does the change detection
// We override the property '_ComputeNonExistentFileProperty' which is responsible // We override the property '_ComputeNonExistentFileProperty' which is responsible
// for recompiling each time - our _ComputeNonExistentFileProperty does nothing, // for recompiling each time - our _ComputeNonExistentFileProperty does nothing,
// which re-enables the MSBuild's usual change detection // which re-enables the MSBuild's usual change detection
project.Targets.AddNewTarget("_ComputeNonExistentFileProperty"); project.Targets.AddNewTarget("_ComputeNonExistentFileProperty");
*/
foreach (string additionalImport in currentJob.AdditionalImports) { foreach (string additionalImport in currentJob.AdditionalImports) {
project.AddNewImport(additionalImport, null); project.AddNewImport(additionalImport, null);

Loading…
Cancel
Save