Browse Source

Fixed SD2-1477 - Unable to save project settings in .user file.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3753 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
653e996b6f
  1. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs
  2. 4
      src/Main/Base/Project/Src/Project/AbstractProject.cs
  3. 2
      src/Main/Base/Project/Src/Project/CompilableProject.cs
  4. 185
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
  5. 13
      src/Main/Base/Project/Src/Project/MSBuildInternals.cs
  6. 11
      src/Main/Base/Project/Src/Project/Solution/Solution.cs

4
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs

@ -243,7 +243,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
ComboBox targetFrameworkComboBox = (ComboBox)ControlDictionary["targetFrameworkComboBox"]; ComboBox targetFrameworkComboBox = (ComboBox)ControlDictionary["targetFrameworkComboBox"];
if (convertProjectToMSBuild35Button != null) { if (convertProjectToMSBuild35Button != null) {
if (project.MinimumSolutionVersion == Solution.SolutionVersionVS05) { if (project.MinimumSolutionVersion == Solution.SolutionVersionVS2005) {
// VS05 project // VS05 project
targetFrameworkComboBox.Enabled = false; targetFrameworkComboBox.Enabled = false;
convertProjectToMSBuild35Button.Click += OnConvertProjectToMSBuild35ButtonClick; convertProjectToMSBuild35Button.Click += OnConvertProjectToMSBuild35ButtonClick;
@ -284,7 +284,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
} else { } else {
project.ConvertToMSBuild35(dlg.ChangeTargetFramework); project.ConvertToMSBuild35(dlg.ChangeTargetFramework);
} }
if (project.MinimumSolutionVersion == Solution.SolutionVersionVS05) if (project.MinimumSolutionVersion == Solution.SolutionVersionVS2005)
throw new InvalidOperationException("Project did not convert to MSBuild 3.5"); throw new InvalidOperationException("Project did not convert to MSBuild 3.5");
ProjectService.SaveSolution(); ProjectService.SaveSolution();
InitTargetFramework(); InitTargetFramework();

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

@ -455,7 +455,7 @@ namespace ICSharpCode.SharpDevelop.Project
[Browsable(false)] [Browsable(false)]
public virtual int MinimumSolutionVersion { public virtual int MinimumSolutionVersion {
get { return Solution.SolutionVersionVS05; } get { return Solution.SolutionVersionVS2005; }
} }
public virtual void ResolveAssemblyReferences() public virtual void ResolveAssemblyReferences()
@ -471,6 +471,7 @@ namespace ICSharpCode.SharpDevelop.Project
public virtual ICollection<IBuildable> GetBuildDependencies(ProjectBuildOptions buildOptions) public virtual ICollection<IBuildable> GetBuildDependencies(ProjectBuildOptions buildOptions)
{ {
lock (SyncRoot) {
List<IBuildable> result = new List<IBuildable>(); List<IBuildable> result = new List<IBuildable>();
foreach (ProjectSection section in this.ProjectSections) { foreach (ProjectSection section in this.ProjectSections) {
if (section.Name == "ProjectDependencies") { if (section.Name == "ProjectDependencies") {
@ -486,4 +487,5 @@ namespace ICSharpCode.SharpDevelop.Project
return result; return result;
} }
} }
}
} }

2
src/Main/Base/Project/Src/Project/CompilableProject.cs

@ -359,6 +359,7 @@ namespace ICSharpCode.SharpDevelop.Project
protected override void OnPropertyChanged(ProjectPropertyChangedEventArgs e) protected override void OnPropertyChanged(ProjectPropertyChangedEventArgs e)
{ {
base.OnPropertyChanged(e); base.OnPropertyChanged(e);
if (!isLoading) {
if (reparseReferencesSensitiveProperties.Contains(e.PropertyName)) { if (reparseReferencesSensitiveProperties.Contains(e.PropertyName)) {
ParserService.Reparse(this, true, false); ParserService.Reparse(this, true, false);
} }
@ -366,6 +367,7 @@ namespace ICSharpCode.SharpDevelop.Project
ParserService.Reparse(this, false, true); ParserService.Reparse(this, false, true);
} }
} }
}
[Browsable(false)] [Browsable(false)]
public override string TypeGuid { public override string TypeGuid {

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

@ -22,6 +22,10 @@ namespace ICSharpCode.SharpDevelop.Project
{ {
/// <summary> /// <summary>
/// A project that is based on an MSBuild project file. /// A project that is based on an MSBuild project file.
///
/// Thread-safety: most members are thread-safe, but direct accesses on the underlying MSBuildProject
/// require locking on the SyncRoot. Methods that return underlying MSBuild objects require that
/// the caller locks on the SyncRoot.
/// </summary> /// </summary>
public class MSBuildBasedProject : AbstractProject, IProjectItemListProvider, IProjectAllowChangeConfigurations public class MSBuildBasedProject : AbstractProject, IProjectItemListProvider, IProjectAllowChangeConfigurations
{ {
@ -30,6 +34,11 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
MSBuild.Project project; MSBuild.Project project;
/// <summary>
/// The '.user' part of the project.
/// </summary>
MSBuild.Project userProject;
/// <summary> /// <summary>
/// A list of project properties that are saved after the normal properties. /// A list of project properties that are saved after the normal properties.
/// Use this for properties that could reference other properties, e.g. /// Use this for properties that could reference other properties, e.g.
@ -45,6 +54,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (engine == null) if (engine == null)
throw new ArgumentNullException("engine"); throw new ArgumentNullException("engine");
this.project = engine.CreateNewProject(); this.project = engine.CreateNewProject();
this.userProject = engine.CreateNewProject();
} }
/// <summary> /// <summary>
@ -60,6 +70,9 @@ namespace ICSharpCode.SharpDevelop.Project
base.Dispose(); base.Dispose();
// unload evaluatingTempProject if necessary: // unload evaluatingTempProject if necessary:
MSBuildInternals.EnsureCorrectTempProject(project, null, null, ref evaluatingTempProject); MSBuildInternals.EnsureCorrectTempProject(project, null, null, ref evaluatingTempProject);
// unload project + userProject:
project.ParentEngine.UnloadProject(project);
userProject.ParentEngine.UnloadProject(userProject);
} }
public override int MinimumSolutionVersion { public override int MinimumSolutionVersion {
@ -68,9 +81,9 @@ namespace ICSharpCode.SharpDevelop.Project
if (string.IsNullOrEmpty(project.DefaultToolsVersion) if (string.IsNullOrEmpty(project.DefaultToolsVersion)
|| project.DefaultToolsVersion == "2.0") || project.DefaultToolsVersion == "2.0")
{ {
return Solution.SolutionVersionVS05; return Solution.SolutionVersionVS2005;
} else { } else {
return Solution.SolutionVersionVS08; return Solution.SolutionVersionVS2008;
} }
} }
} }
@ -195,9 +208,11 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
protected void AddImport(string projectFile, string condition) protected void AddImport(string projectFile, string condition)
{ {
lock (SyncRoot) {
project.AddNewImport(projectFile, condition); project.AddNewImport(projectFile, condition);
CreateItemsListFromMSBuild(); CreateItemsListFromMSBuild();
} }
}
#endregion #endregion
#region Get Property #region Get Property
@ -317,14 +332,19 @@ namespace ICSharpCode.SharpDevelop.Project
protected bool EvaluateMSBuildCondition(string configuration, string platform, protected bool EvaluateMSBuildCondition(string configuration, string platform,
string condition) string condition)
{ {
lock (SyncRoot) {
return MSBuildInternals.EvaluateCondition(project, configuration, platform, condition, return MSBuildInternals.EvaluateCondition(project, configuration, platform, condition,
ref evaluatingTempProject); ref evaluatingTempProject);
} }
}
/// <summary> /// <summary>
/// Finds the <c>BuildProperty</c> object used to store <paramref name="propertyName"/> /// Finds the <c>BuildProperty</c> object used to store <paramref name="propertyName"/>
/// in the specified configuration/platform. /// in the specified configuration/platform.
/// </summary> /// </summary>
///
/// Warning: you need to lock(project.SyncRoot) around calls to GetAllProperties
/// until you no longer need to access the BuildProperty objects!
/// <param name="configuration">The configuration to use.</param> /// <param name="configuration">The configuration to use.</param>
/// <param name="platform">The platform to use.</param> /// <param name="platform">The platform to use.</param>
/// <param name="propertyName">The property to look for.</param> /// <param name="propertyName">The property to look for.</param>
@ -339,6 +359,31 @@ namespace ICSharpCode.SharpDevelop.Project
if (string.IsNullOrEmpty(configuration)) configuration = ActiveConfiguration; if (string.IsNullOrEmpty(configuration)) configuration = ActiveConfiguration;
if (string.IsNullOrEmpty(platform)) platform = ActivePlatform; if (string.IsNullOrEmpty(platform)) platform = ActivePlatform;
// First try main project file
MSBuild.BuildProperty p = FindPropertyObjectInternal(project, configuration, platform, propertyName, out group);
if (p != null) {
location = MSBuildInternals.GetLocationFromCondition(group.Condition);
return p;
} else {
// try user project file
p = FindPropertyObjectInternal(userProject, configuration, platform, propertyName, out group);
if (p != null) {
location = PropertyStorageLocations.UserFile
| MSBuildInternals.GetLocationFromCondition(group.Condition);
return p;
} else {
location = PropertyStorageLocations.Unknown;
group = null;
return null;
}
}
}
MSBuild.BuildProperty FindPropertyObjectInternal(MSBuild.Project project,
string configuration, string platform,
string propertyName,
out MSBuild.BuildPropertyGroup group)
{
// We need to use ToList because EvaluateMSBuildCondition invalidates the list // We need to use ToList because EvaluateMSBuildCondition invalidates the list
// of property groups. // of property groups.
foreach (MSBuild.BuildPropertyGroup g foreach (MSBuild.BuildPropertyGroup g
@ -351,13 +396,10 @@ namespace ICSharpCode.SharpDevelop.Project
if (property == null) if (property == null)
continue; continue;
if (EvaluateMSBuildCondition(configuration, platform, g.Condition)) { if (EvaluateMSBuildCondition(configuration, platform, g.Condition)) {
location = MSBuildInternals.GetLocationFromCondition(g.Condition);
group = g; group = g;
return property; return property;
} }
} }
location = PropertyStorageLocations.Unknown;
group = null; group = null;
return null; return null;
} }
@ -370,8 +412,16 @@ namespace ICSharpCode.SharpDevelop.Project
/// <param name="platform">Platform filter. Only use properties from this platform. /// <param name="platform">Platform filter. Only use properties from this platform.
/// Use <c>null</c> to allow properties from all platforms.</param> /// Use <c>null</c> to allow properties from all platforms.</param>
/// <param name="propertyName">The name of the property</param> /// <param name="propertyName">The name of the property</param>
string GetAnyUnevaluatedPropertyValue(string configuration, string platform, string GetAnyUnevaluatedPropertyValue(string configuration, string platform, string propertyName)
string propertyName) {
// first try main project file, then try user project file
MSBuild.BuildProperty p = GetAnyUnevaluatedProperty(project, configuration, platform, propertyName);
if (p == null)
p = GetAnyUnevaluatedProperty(userProject, configuration, platform, propertyName);
return p != null ? p.Value : null;
}
static MSBuild.BuildProperty GetAnyUnevaluatedProperty(MSBuild.Project project, string configuration, string platform, string propertyName)
{ {
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) { foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) {
if (g.IsImported) { if (g.IsImported) {
@ -387,7 +437,7 @@ namespace ICSharpCode.SharpDevelop.Project
if ((configuration == null || configuration == gConfiguration || gConfiguration == null) if ((configuration == null || configuration == gConfiguration || gConfiguration == null)
&& (platform == null || platform == gPlatform || gPlatform == null)) && (platform == null || platform == gPlatform || gPlatform == null))
{ {
return property.Value; return property;
} }
} }
return null; return null;
@ -395,6 +445,9 @@ namespace ICSharpCode.SharpDevelop.Project
/// <summary> /// <summary>
/// Get all instances of the specified property. /// Get all instances of the specified property.
///
/// Warning: you need to lock(project.SyncRoot) around calls to GetAllProperties
/// until you no longer need to access the BuildProperty objects!
/// </summary> /// </summary>
public IList<MSBuild.BuildProperty> GetAllProperties(string propertyName) public IList<MSBuild.BuildProperty> GetAllProperties(string propertyName)
{ {
@ -406,6 +459,13 @@ namespace ICSharpCode.SharpDevelop.Project
l.Add(property); l.Add(property);
} }
} }
foreach (MSBuild.BuildPropertyGroup g in userProject.PropertyGroups) {
if (g.IsImported) continue;
MSBuild.BuildProperty property = MSBuildInternals.GetProperty(g, propertyName);
if (property != null) {
l.Add(property);
}
}
return l; return l;
} }
#endregion #endregion
@ -432,6 +492,13 @@ namespace ICSharpCode.SharpDevelop.Project
return MSBuildInternals.GetLocationFromCondition(g.Condition); return MSBuildInternals.GetLocationFromCondition(g.Condition);
} }
} }
foreach (MSBuild.BuildPropertyGroup g in userProject.PropertyGroups) {
if (g.IsImported) continue;
if (MSBuildInternals.GetProperty(g, propertyName) != null) {
return PropertyStorageLocations.UserFile |
MSBuildInternals.GetLocationFromCondition(g.Condition);
}
}
return PropertyStorageLocations.Unknown; return PropertyStorageLocations.Unknown;
} }
@ -513,12 +580,19 @@ namespace ICSharpCode.SharpDevelop.Project
if (location == PropertyStorageLocations.Unchanged) { if (location == PropertyStorageLocations.Unchanged) {
location = oldLocation; location = oldLocation;
} }
// determine the insertion position for the property
MSBuild.PropertyPosition propertyInsertionPosition; MSBuild.PropertyPosition propertyInsertionPosition;
if (saveAfterImportsProperties.Contains(propertyName)) { if (saveAfterImportsProperties.Contains(propertyName)) {
propertyInsertionPosition = MSBuild.PropertyPosition.UseExistingOrCreateAfterLastImport; propertyInsertionPosition = MSBuild.PropertyPosition.UseExistingOrCreateAfterLastImport;
} else { } else {
propertyInsertionPosition = MSBuild.PropertyPosition.UseExistingOrCreateAfterLastPropertyGroup; propertyInsertionPosition = MSBuild.PropertyPosition.UseExistingOrCreateAfterLastPropertyGroup;
} }
// get the project file where the property should be stored
MSBuild.Project targetProject;
if ((location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile)
targetProject = userProject;
else
targetProject = project;
if (oldLocation != location) { if (oldLocation != location) {
// move existing properties to new location, then use the normal property // move existing properties to new location, then use the normal property
@ -542,7 +616,7 @@ namespace ICSharpCode.SharpDevelop.Project
// Recreate the property using the saved value // Recreate the property using the saved value
foreach (KeyValuePair<string, string> pair in oldValuesConf) { foreach (KeyValuePair<string, string> pair in oldValuesConf) {
if (pair.Value != null) { if (pair.Value != null) {
project.SetProperty(propertyName, pair.Value, targetProject.SetProperty(propertyName, pair.Value,
CreateCondition(pair.Key, null, location), CreateCondition(pair.Key, null, location),
propertyInsertionPosition, propertyInsertionPosition,
false); false);
@ -562,7 +636,7 @@ namespace ICSharpCode.SharpDevelop.Project
// Recreate the property using the saved value // Recreate the property using the saved value
foreach (KeyValuePair<string, string> pair in oldValuesPlat) { foreach (KeyValuePair<string, string> pair in oldValuesPlat) {
if (pair.Value != null) { if (pair.Value != null) {
project.SetProperty(propertyName, pair.Value, targetProject.SetProperty(propertyName, pair.Value,
CreateCondition(null, pair.Key, location), CreateCondition(null, pair.Key, location),
propertyInsertionPosition, propertyInsertionPosition,
false); false);
@ -584,7 +658,7 @@ namespace ICSharpCode.SharpDevelop.Project
// Recreate the property using the saved value // Recreate the property using the saved value
foreach (KeyValuePair<StringPair, string> pair in oldValues) { foreach (KeyValuePair<StringPair, string> pair in oldValues) {
if (pair.Value != null) { if (pair.Value != null) {
project.SetProperty(propertyName, pair.Value, targetProject.SetProperty(propertyName, pair.Value,
CreateCondition(pair.Key.First, pair.Key.Second, location), CreateCondition(pair.Key.First, pair.Key.Second, location),
propertyInsertionPosition, propertyInsertionPosition,
false); false);
@ -596,11 +670,12 @@ namespace ICSharpCode.SharpDevelop.Project
} }
// update existingProperty and existingPropertyGroup after the move operation // update existingProperty and existingPropertyGroup after the move operation
PropertyStorageLocations tmpLocation;
existingProperty = FindPropertyObject(configuration, existingProperty = FindPropertyObject(configuration,
platform, platform,
propertyName, propertyName,
out existingPropertyGroup, out existingPropertyGroup,
out oldLocation); out tmpLocation);
} }
ProjectPropertyChangedEventArgs args; ProjectPropertyChangedEventArgs args;
args = new ProjectPropertyChangedEventArgs(propertyName); args = new ProjectPropertyChangedEventArgs(propertyName);
@ -618,17 +693,17 @@ namespace ICSharpCode.SharpDevelop.Project
existingPropertyGroup.RemoveProperty(existingProperty); existingPropertyGroup.RemoveProperty(existingProperty);
if (existingPropertyGroup.Count == 0) { if (existingPropertyGroup.Count == 0) {
project.RemovePropertyGroup(existingPropertyGroup); targetProject.RemovePropertyGroup(existingPropertyGroup);
} }
} }
} else if (existingPropertyGroup != null && existingProperty != null) { } else if (existingPropertyGroup != null && existingProperty != null) {
args.OldValue = existingProperty.Value; args.OldValue = existingProperty.Value;
project.SetProperty(propertyName, newValue, targetProject.SetProperty(propertyName, newValue,
existingPropertyGroup.Condition, existingPropertyGroup.Condition,
propertyInsertionPosition, propertyInsertionPosition,
treatPropertyValueAsLiteral); treatPropertyValueAsLiteral);
} else { } else {
project.SetProperty(propertyName, newValue, targetProject.SetProperty(propertyName, newValue,
CreateCondition(configuration, platform, location), CreateCondition(configuration, platform, location),
propertyInsertionPosition, propertyInsertionPosition,
treatPropertyValueAsLiteral); treatPropertyValueAsLiteral);
@ -640,6 +715,12 @@ namespace ICSharpCode.SharpDevelop.Project
/// Removes the property from all configurations and platforms. /// Removes the property from all configurations and platforms.
/// </summary> /// </summary>
void RemovePropertyCompletely(string propertyName) void RemovePropertyCompletely(string propertyName)
{
RemovePropertyCompletely(project, propertyName);
RemovePropertyCompletely(userProject, propertyName);
}
static void RemovePropertyCompletely(MSBuild.Project project, string propertyName)
{ {
List<MSBuild.BuildPropertyGroup> emptiedGroups = new List<MSBuild.BuildPropertyGroup>(); List<MSBuild.BuildPropertyGroup> emptiedGroups = new List<MSBuild.BuildPropertyGroup>();
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) { foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) {
@ -752,9 +833,10 @@ namespace ICSharpCode.SharpDevelop.Project
items.Add(CreateProjectItem(item)); items.Add(CreateProjectItem(item));
} }
}
ClearFindFileCache(); ClearFindFileCache();
} }
}
void IProjectItemListProvider.AddProjectItem(ProjectItem item) void IProjectItemListProvider.AddProjectItem(ProjectItem item)
{ {
@ -890,8 +972,18 @@ namespace ICSharpCode.SharpDevelop.Project
protected virtual void LoadProject(string fileName) protected virtual void LoadProject(string fileName)
{ {
lock (SyncRoot) {
isLoading = true; isLoading = true;
try { try {
LoadProjectInternal(fileName);
} finally {
isLoading = false;
}
}
}
void LoadProjectInternal(string fileName)
{
this.FileName = fileName; this.FileName = fileName;
InitializeMSBuildProject(project); InitializeMSBuildProject(project);
@ -928,6 +1020,16 @@ namespace ICSharpCode.SharpDevelop.Project
throw new ProjectLoadException(ex.Message, ex); throw new ProjectLoadException(ex.Message, ex);
} }
} }
string userFileName = fileName + ".user";
if (File.Exists(userFileName)) {
try {
userProject.Load(userFileName);
} catch (MSBuild.InvalidProjectFileException ex) {
throw new ProjectLoadException("Error loading user part " + userFileName + ":\n" + ex.Message);
}
}
this.ActiveConfiguration = GetEvaluatedProperty("Configuration") ?? this.ActiveConfiguration; this.ActiveConfiguration = GetEvaluatedProperty("Configuration") ?? this.ActiveConfiguration;
this.ActivePlatform = GetEvaluatedProperty("Platform") ?? this.ActivePlatform; this.ActivePlatform = GetEvaluatedProperty("Platform") ?? this.ActivePlatform;
@ -940,9 +1042,6 @@ namespace ICSharpCode.SharpDevelop.Project
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
base.IdGuid = GetEvaluatedProperty(ProjectGuidPropertyName); base.IdGuid = GetEvaluatedProperty(ProjectGuidPropertyName);
} finally {
isLoading = false;
}
} }
[Browsable(false)] [Browsable(false)]
@ -955,7 +1054,10 @@ namespace ICSharpCode.SharpDevelop.Project
try { try {
// save fixed project // save fixed project
project.Save(this.FileName); project.Save(this.FileName);
} catch {} } catch (IOException) {
} catch (AccessViolationException) {
// Ignore errors writing the fixed project file
}
} }
base.IdGuid = value; base.IdGuid = value;
} }
@ -967,6 +1069,11 @@ namespace ICSharpCode.SharpDevelop.Project
{ {
lock (SyncRoot) { lock (SyncRoot) {
project.Save(fileName); project.Save(fileName);
bool userProjectDirty = userProject.IsDirty;
string userFile = fileName + ".user";
if (File.Exists(userFile) || userProject.PropertyGroups.Count > 0) {
userProject.Save(userFile);
}
} }
} }
#endregion #endregion
@ -1000,21 +1107,25 @@ namespace ICSharpCode.SharpDevelop.Project
public override ICollection<string> ConfigurationNames { public override ICollection<string> ConfigurationNames {
get { get {
lock (SyncRoot) {
if (configurationNames == null) { if (configurationNames == null) {
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
} }
return configurationNames; return configurationNames;
} }
} }
}
public override ICollection<string> PlatformNames { public override ICollection<string> PlatformNames {
get { get {
lock (SyncRoot) {
if (platformNames == null) { if (platformNames == null) {
LoadConfigurationPlatformNamesFromMSBuild(); LoadConfigurationPlatformNamesFromMSBuild();
} }
return platformNames; return platformNames;
} }
} }
}
/// <summary> /// <summary>
/// Load available configurations and platforms from the project file /// Load available configurations and platforms from the project file
@ -1025,6 +1136,25 @@ namespace ICSharpCode.SharpDevelop.Project
Set<string> configurationNames = new Set<string>(); Set<string> configurationNames = new Set<string>();
Set<string> platformNames = new Set<string>(); Set<string> platformNames = new Set<string>();
LoadConfigurationPlatformNamesFromMSBuildInternal(project, configurationNames, platformNames);
LoadConfigurationPlatformNamesFromMSBuildInternal(userProject, configurationNames, platformNames);
if (configurationNames.Count == 0) {
configurationNames.Add("Debug");
configurationNames.Add("Release");
}
if (platformNames.Count == 0) {
platformNames.Add("AnyCPU");
}
this.configurationNames = configurationNames.AsReadOnly();
this.platformNames = platformNames.AsReadOnly();
}
static void LoadConfigurationPlatformNamesFromMSBuildInternal(
MSBuild.Project project,
Set<string> configurationNames, Set<string> platformNames)
{
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) { foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) {
if (g.IsImported) { if (g.IsImported) {
continue; continue;
@ -1039,9 +1169,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
string gConfiguration, gPlatform; string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition, MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition, out gConfiguration, out gPlatform);
out gConfiguration,
out gPlatform);
if (gConfiguration != null) { if (gConfiguration != null) {
configurationNames.Add(gConfiguration); configurationNames.Add(gConfiguration);
} }
@ -1049,17 +1177,6 @@ namespace ICSharpCode.SharpDevelop.Project
platformNames.Add(gPlatform); platformNames.Add(gPlatform);
} }
} }
if (configurationNames.Count == 0) {
configurationNames.Add("Debug");
configurationNames.Add("Release");
}
if (platformNames.Count == 0) {
platformNames.Add("AnyCPU");
}
this.configurationNames = configurationNames.AsReadOnly();
this.platformNames = platformNames.AsReadOnly();
} }
#endregion #endregion

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

@ -308,6 +308,11 @@ namespace ICSharpCode.SharpDevelop.Project
} }
static void EndXmlManipulation(MSBuild.Project project) static void EndXmlManipulation(MSBuild.Project project)
{
MarkProjectAsDirtyForReprocessXml(project);
}
internal static void MarkProjectAsDirtyForReprocessXml(MSBuild.Project project)
{ {
typeof(MSBuild.Project).InvokeMember( typeof(MSBuild.Project).InvokeMember(
"MarkProjectAsDirtyForReprocessXml", "MarkProjectAsDirtyForReprocessXml",
@ -318,14 +323,14 @@ namespace ICSharpCode.SharpDevelop.Project
internal static void ResolveAssemblyReferences(MSBuildBasedProject baseProject, ReferenceProjectItem[] referenceReplacements) internal static void ResolveAssemblyReferences(MSBuildBasedProject baseProject, ReferenceProjectItem[] referenceReplacements)
{ {
MSBuild.Engine engine; MSBuild.Engine tempEngine;
MSBuild.Project tempProject; MSBuild.Project tempProject;
IEnumerable<ReferenceProjectItem> references; IEnumerable<ReferenceProjectItem> references;
lock (baseProject.SyncRoot) { lock (baseProject.SyncRoot) {
// create a copy of the project // create a copy of the project
engine = CreateEngine(); tempEngine = CreateEngine();
tempProject = engine.CreateNewProject(); tempProject = tempEngine.CreateNewProject();
// tell MSBuild the path so that projects containing <Import Project="relativePath" /> // tell MSBuild the path so that projects containing <Import Project="relativePath" />
// can be loaded // can be loaded
tempProject.FullFileName = baseProject.MSBuildProject.FullFileName; tempProject.FullFileName = baseProject.MSBuildProject.FullFileName;
@ -402,6 +407,8 @@ namespace ICSharpCode.SharpDevelop.Project
LoggingService.Warn("Unknown item " + originalInclude); LoggingService.Warn("Unknown item " + originalInclude);
} }
} }
tempEngine.UnloadAllProjects(); // unload temp project
} }
} }
} }

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

@ -28,7 +28,12 @@ namespace ICSharpCode.SharpDevelop.Project
public class Solution : SolutionFolder, IDisposable, IMSBuildEngineProvider, IBuildable public class Solution : SolutionFolder, IDisposable, IMSBuildEngineProvider, IBuildable
{ {
public const int SolutionVersionVS2005 = 9;
public const int SolutionVersionVS2008 = 10;
[Obsolete("Use SolutionVersionVS2005 instead")]
public const int SolutionVersionVS05 = 9; public const int SolutionVersionVS05 = 9;
[Obsolete("Use SolutionVersionVS2008 instead")]
public const int SolutionVersionVS08 = 10; public const int SolutionVersionVS08 = 10;
/// <summary>contains &lt;GUID, (IProject/ISolutionFolder)&gt; pairs.</summary> /// <summary>contains &lt;GUID, (IProject/ISolutionFolder)&gt; pairs.</summary>
@ -351,16 +356,16 @@ namespace ICSharpCode.SharpDevelop.Project
// we need to specify UTF8 because MSBuild needs the BOM // we need to specify UTF8 because MSBuild needs the BOM
using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8)) { using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8)) {
sw.WriteLine(); sw.WriteLine();
int versionNumber = SolutionVersionVS05; int versionNumber = SolutionVersionVS2005;
foreach (IProject p in this.Projects) { foreach (IProject p in this.Projects) {
if (p.MinimumSolutionVersion > versionNumber) if (p.MinimumSolutionVersion > versionNumber)
versionNumber = p.MinimumSolutionVersion; versionNumber = p.MinimumSolutionVersion;
} }
sw.WriteLine("Microsoft Visual Studio Solution File, Format Version " + versionNumber + ".00"); sw.WriteLine("Microsoft Visual Studio Solution File, Format Version " + versionNumber + ".00");
if (versionNumber == SolutionVersionVS05) { if (versionNumber == SolutionVersionVS2005) {
sw.WriteLine("# Visual Studio 2005"); sw.WriteLine("# Visual Studio 2005");
} else if (versionNumber == SolutionVersionVS08) { } else if (versionNumber == SolutionVersionVS2008) {
sw.WriteLine("# Visual Studio 2008"); sw.WriteLine("# Visual Studio 2008");
} }
sw.WriteLine("# SharpDevelop " + RevisionClass.FullVersion); sw.WriteLine("# SharpDevelop " + RevisionClass.FullVersion);

Loading…
Cancel
Save