Browse Source

Allow changing the active solution configuration in the build menu.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@892 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e46db83c0a
  1. 10
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 29
      src/Main/Base/Project/Src/Commands/BuildCommands.cs
  3. 38
      src/Main/Base/Project/Src/Project/AbstractProject.cs
  4. 9
      src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs
  5. 3
      src/Main/Base/Project/Src/Project/IProject.cs
  6. 36
      src/Main/Base/Project/Src/Project/MSBuildEngine.cs
  7. 17
      src/Main/Base/Project/Src/Project/MSBuildProject.cs
  8. 74
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  9. 47
      src/Main/Base/Project/Src/Project/Solution/SolutionPreferences.cs

10
AddIns/ICSharpCode.SharpDevelop.addin

@ -1173,7 +1173,7 @@ @@ -1173,7 +1173,7 @@
</MenuItem>
</Condition> <!-- end PROJECT menu -->
<MenuItem id = "Run" label = "${res:XML.MainMenu.BuildMenu}" type="Menu">
<MenuItem id = "Build" label = "${res:XML.MainMenu.BuildMenu}" type="Menu">
<ComplexCondition action="Disable">
<Or>
<And>
@ -1211,10 +1211,16 @@ @@ -1211,10 +1211,16 @@
<MenuItem id = "Clean project"
label = "${res:XML.MainMenu.BuildMenu.CleanProject}"
class = "ICSharpCode.SharpDevelop.Project.Commands.CleanProject"/>
<MenuItem id = "Publis&amp;h project"
<MenuItem id = "Publish project"
label = "${res:XML.MainMenu.BuildMenu.PublishProject}"
class = "ICSharpCode.SharpDevelop.Project.Commands.PublishProject"/>
</Condition>
<MenuItem id = "Separator2" type = "Separator" />
<MenuItem id = "SetConfiguration"
label = "Set configuration"
type = "Menu">
<MenuItem id = "ConfigurationBuilder" type = "Builder" class = "ICSharpCode.SharpDevelop.Project.Commands.SetConfigurationMenuBuilder"/>
</MenuItem>
</ComplexCondition>
</MenuItem> <!-- end RUN menu -->

29
src/Main/Base/Project/Src/Commands/BuildCommands.cs

@ -1,18 +1,19 @@ @@ -1,18 +1,19 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="mike@icsharpcode.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Project.Commands
{
public class Build : AbstractMenuCommand
@ -167,4 +168,28 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -167,4 +168,28 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
}
}
}
public class SetConfigurationMenuBuilder : ISubmenuBuilder
{
public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
{
if (ProjectService.OpenSolution == null)
return new ToolStripItem[0];
IList<string> configurationNames = ProjectService.OpenSolution.GetConfigurationNames();
string activeConfiguration = ProjectService.OpenSolution.Preferences.ActiveConfiguration;
ToolStripMenuItem[] items = new ToolStripMenuItem[configurationNames.Count];
for (int i = 0; i < items.Length; i++) {
items[i] = new ToolStripMenuItem(configurationNames[i]);
items[i].Click += SetConfigurationItemClick;
items[i].Checked = activeConfiguration == configurationNames[i];
}
return items;
}
void SetConfigurationItemClick(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
ProjectService.OpenSolution.Preferences.ActiveConfiguration = item.Text;
}
}
}

38
src/Main/Base/Project/Src/Project/AbstractProject.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Project
return key.Substring(key.IndexOf('|') + 1);
}
public string[] GetConfigurationNames()
public List<string> GetConfigurationNames()
{
List<string> configurationNames = new List<string>();
foreach (string key in configurations.Keys) {
@ -61,11 +61,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -61,11 +61,10 @@ namespace ICSharpCode.SharpDevelop.Project
if (!configurationNames.Contains(this.Configuration)) {
configurationNames.Add(this.Configuration);
}
configurationNames.Sort();
return configurationNames.ToArray();
return configurationNames;
}
public string[] GetPlatformNames()
public List<string> GetPlatformNames()
{
List<string> platformNames = new List<string>();
foreach (string key in configurations.Keys) {
@ -83,8 +82,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -83,8 +82,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (!platformNames.Contains(this.Platform)) {
platformNames.Add(this.Platform);
}
platformNames.Sort();
return platformNames.ToArray();
return platformNames;
}
/// <summary>
@ -211,8 +209,28 @@ namespace ICSharpCode.SharpDevelop.Project @@ -211,8 +209,28 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
[Browsable(false)]
string activeConfiguration, activePlatform;
public string Platform {
get {
return activePlatform;
}
set {
activePlatform = value;
}
}
public string Configuration {
get {
return activeConfiguration;
}
set {
activeConfiguration = value;
}
}
[Browsable(false)]
public string DefaultConfiguration {
get {
// is always stored in BaseConfiguration
return BaseConfiguration["Configuration"];
@ -223,7 +241,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -223,7 +241,7 @@ namespace ICSharpCode.SharpDevelop.Project
}
[Browsable(false)]
public string Platform {
public string DefaultPlatform {
get {
// is always stored in BaseConfiguration
return BaseConfiguration["Platform"];
@ -513,8 +531,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -513,8 +531,8 @@ namespace ICSharpCode.SharpDevelop.Project
}
if (oldBaseValue != null) {
// copy old base value to all configurations
string[] configurationNames = GetConfigurationNames();
string[] platformNames = GetPlatformNames();
IEnumerable<string> configurationNames = GetConfigurationNames();
IEnumerable<string> platformNames = GetPlatformNames();
switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
foreach (string cN in configurationNames) {

9
src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs

@ -518,10 +518,15 @@ namespace ICSharpCode.SharpDevelop.Project @@ -518,10 +518,15 @@ namespace ICSharpCode.SharpDevelop.Project
void FillBoxes()
{
List<string> items;
configurationComboBox.Items.Clear();
configurationComboBox.Items.AddRange(helper.Project.GetConfigurationNames());
items = helper.Project.GetConfigurationNames();
items.Sort();
configurationComboBox.Items.AddRange(items.ToArray());
platformComboBox.Items.Clear();
platformComboBox.Items.AddRange(helper.Project.GetPlatformNames());
items = helper.Project.GetPlatformNames();
items.Sort();
platformComboBox.Items.AddRange(items.ToArray());
ResetIndex();
}

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

@ -58,10 +58,11 @@ namespace ICSharpCode.SharpDevelop.Project @@ -58,10 +58,11 @@ namespace ICSharpCode.SharpDevelop.Project
string Configuration {
get;
set;
}
string Platform {
get;
set;
}
string AssemblyName {

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

@ -58,6 +58,36 @@ namespace ICSharpCode.SharpDevelop.Project @@ -58,6 +58,36 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
string configuration;
/// <summary>
/// The configuration of the solution or project that should be builded.
/// Use null to build the default configuration.
/// </summary>
public string Configuration {
get {
return configuration;
}
set {
configuration = value;
}
}
string platform;
/// <summary>
/// The platform of the solution or project that should be builded.
/// Use null to build the default platform.
/// </summary>
public string Platform {
get {
return platform;
}
set {
platform = value;
}
}
public CompilerResults Run(string buildFile)
{
return Run(buildFile, null);
@ -108,6 +138,12 @@ namespace ICSharpCode.SharpDevelop.Project @@ -108,6 +138,12 @@ namespace ICSharpCode.SharpDevelop.Project
LoggingService.Debug("Run MSBuild on " + buildFile);
Engine engine = new Engine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory());
if (this.engine.Configuration != null) {
engine.GlobalProperties.SetProperty("Configuration", this.engine.Configuration);
}
if (this.engine.Platform != null) {
engine.GlobalProperties.SetProperty("Platform", this.engine.Platform);
}
foreach (KeyValuePair<string, string> entry in MSBuildProperties) {
engine.GlobalProperties.SetProperty(entry.Key, entry.Value);
}

17
src/Main/Base/Project/Src/Project/MSBuildProject.cs

@ -422,11 +422,13 @@ namespace ICSharpCode.SharpDevelop.Project @@ -422,11 +422,13 @@ namespace ICSharpCode.SharpDevelop.Project
// isDirty = TaskService.Errors != 0;
// }
public static CompilerResults RunMSBuild(string fileName, string target)
public static CompilerResults RunMSBuild(string fileName, string target, string configuration, string platform)
{
WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).BringPadToFront();
// BeforeBuild();
MSBuildEngine engine = new MSBuildEngine();
engine.Configuration = configuration;
engine.Platform = platform;
engine.MessageView = TaskService.BuildMessageViewCategory;
if (target == null) {
return engine.Run(fileName);
@ -435,26 +437,31 @@ namespace ICSharpCode.SharpDevelop.Project @@ -435,26 +437,31 @@ namespace ICSharpCode.SharpDevelop.Project
// AfterBuild();
}
public CompilerResults RunMSBuild(string target)
{
return RunMSBuild(this.FileName, target, this.Configuration, this.Platform);
}
public override CompilerResults Build()
{
return RunMSBuild(FileName, "Build");
return RunMSBuild("Build");
}
public override CompilerResults Rebuild()
{
return RunMSBuild(FileName, "Rebuild");
return RunMSBuild("Rebuild");
}
public override CompilerResults Clean()
{
CompilerResults result = RunMSBuild(FileName, "Clean");
CompilerResults result = RunMSBuild("Clean");
isDirty = true;
return result;
}
public override CompilerResults Publish()
{
return RunMSBuild(FileName, "Publish");
return RunMSBuild("Publish");
}
public override string ToString()

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

@ -18,9 +18,6 @@ using ICSharpCode.SharpDevelop.Gui; @@ -18,9 +18,6 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Project
{
/// <summary>
/// Description of Solution.
/// </summary>
public class Solution : SolutionFolder, IDisposable
{
// contains <guid>, (IProject/ISolutionFolder) pairs.
@ -486,19 +483,22 @@ namespace ICSharpCode.SharpDevelop.Project @@ -486,19 +483,22 @@ namespace ICSharpCode.SharpDevelop.Project
return true;
}
public const string SolutionPlatformsSectionName = "SolutionConfigurationPlatforms";
public const string ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
public bool FixSolutionConfiguration(IEnumerable<IProject> projects)
{
ProjectSection solSec = null;
ProjectSection prjSec = null;
bool changed = false;
foreach (ProjectSection sec in Sections) {
if (sec.Name == "SolutionConfigurationPlatforms")
if (sec.Name == SolutionPlatformsSectionName)
solSec = sec;
else if (sec.Name == "ProjectConfigurationPlatforms")
else if (sec.Name == ProjectConfigurationSectionName)
prjSec = sec;
}
if (solSec == null) {
solSec = new ProjectSection("SolutionConfigurationPlatforms", "preSolution");
solSec = new ProjectSection(SolutionPlatformsSectionName, "preSolution");
Sections.Insert(0, solSec);
solSec.Items.Add(new SolutionItem("Debug|Any CPU", "Debug|Any CPU"));
solSec.Items.Add(new SolutionItem("Release|Any CPU", "Release|Any CPU"));
@ -506,7 +506,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -506,7 +506,7 @@ namespace ICSharpCode.SharpDevelop.Project
changed = true;
}
if (prjSec == null) {
prjSec = new ProjectSection("ProjectConfigurationPlatforms", "postSolution");
prjSec = new ProjectSection(ProjectConfigurationSectionName, "postSolution");
Sections.Add(prjSec);
LoggingService.Warn("!! Inserted ProjectConfigurationPlatforms !!");
changed = true;
@ -535,6 +535,52 @@ namespace ICSharpCode.SharpDevelop.Project @@ -535,6 +535,52 @@ namespace ICSharpCode.SharpDevelop.Project
return changed;
}
public IList<string> GetConfigurationNames()
{
List<string> configurationNames = new List<string>();
foreach (ProjectSection sec in ProjectService.OpenSolution.Sections) {
if (sec.Name != SolutionPlatformsSectionName)
continue;
foreach (SolutionItem item in sec.Items) {
string name = AbstractProject.GetConfigurationNameFromKey(item.Name);
if (!configurationNames.Contains(name))
configurationNames.Add(name);
}
}
return configurationNames;
}
public IList<string> GetPlatformNames()
{
List<string> platformNames = new List<string>();
foreach (ProjectSection sec in ProjectService.OpenSolution.Sections) {
if (sec.Name != SolutionPlatformsSectionName)
continue;
foreach (SolutionItem item in sec.Items) {
string name = AbstractProject.GetPlatformNameFromKey(item.Name);
if (!platformNames.Contains(name))
platformNames.Add(name);
}
}
return platformNames;
}
public void ApplySolutionConfigurationToProjects(string configuration)
{
// TODO: Use assignments from project configuration section
foreach (IProject p in Projects) {
p.Configuration = configuration;
}
}
public void ApplySolutionPlatformToProjects(string platform)
{
// TODO: Use assignments from project configuration section
foreach (IProject p in Projects) {
p.Platform = platform;
}
}
static Solution solutionBeingLoaded;
public static Solution SolutionBeingLoaded {
@ -582,25 +628,29 @@ namespace ICSharpCode.SharpDevelop.Project @@ -582,25 +628,29 @@ namespace ICSharpCode.SharpDevelop.Project
}
#endregion
public CompilerResults RunMSBuild(string target)
{
return MSBuildProject.RunMSBuild(FileName, target, preferences.ActiveConfiguration, preferences.ActivePlatform);
}
public CompilerResults Build()
{
return MSBuildProject.RunMSBuild(FileName, null);
return RunMSBuild(null);
}
public CompilerResults Rebuild()
{
return MSBuildProject.RunMSBuild(FileName, "Rebuild");
return RunMSBuild("Rebuild");
}
public CompilerResults Clean()
{
return MSBuildProject.RunMSBuild(FileName, "Clean");
return RunMSBuild("Clean");
}
public CompilerResults Publish()
{
return MSBuildProject.RunMSBuild(FileName, "Publish");
return RunMSBuild("Publish");
}
}
}

47
src/Main/Base/Project/Src/Project/Solution/SolutionPreferences.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Project
@ -13,14 +14,15 @@ namespace ICSharpCode.SharpDevelop.Project @@ -13,14 +14,15 @@ namespace ICSharpCode.SharpDevelop.Project
public class SolutionPreferences : IMementoCapable
{
Solution solution;
string startupProject = "";
string activeConfiguration = "Debug";
string activePlatform = "AnyCPU";
internal SolutionPreferences(Solution solution)
{
this.solution = solution;
}
string startupProject = "";
public IProject StartupProject {
get {
if (startupProject.Length == 0)
@ -36,13 +38,37 @@ namespace ICSharpCode.SharpDevelop.Project @@ -36,13 +38,37 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
public string ActiveConfiguration {
get {
return activeConfiguration;
}
set {
if (value == null) throw new ArgumentNullException();
activeConfiguration = value;
solution.ApplySolutionConfigurationToProjects(value);
}
}
public string ActivePlatform {
get {
return activePlatform;
}
set {
if (value == null) throw new ArgumentNullException();
activePlatform = value;
solution.ApplySolutionPlatformToProjects(value);
}
}
/// <summary>
/// Creates a new memento from the state.
/// </summary>
public Properties CreateMemento()
{
Properties p = new Properties();
p.Set("StartupProject", startupProject);
p.Set("StartupProject", startupProject);
p.Set("ActiveConfiguration", activeConfiguration);
p.Set("ActivePlatform", activePlatform);
return p;
}
@ -51,7 +77,20 @@ namespace ICSharpCode.SharpDevelop.Project @@ -51,7 +77,20 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
public void SetMemento(Properties memento)
{
startupProject = memento.Get("StartupProject", "");
startupProject = memento.Get("StartupProject", "");
string configuration = memento.Get("ActiveConfiguration", activeConfiguration);
string platform = memento.Get("ActivePlatform", activePlatform);
// validate configuration and platform:
IList<string> available = solution.GetConfigurationNames();
if (!available.Contains(configuration))
configuration = available[0];
available = solution.GetPlatformNames();
if (!available.Contains(platform))
platform = available[0];
this.ActiveConfiguration = configuration;
this.ActivePlatform = platform;
}
}
}

Loading…
Cancel
Save