Browse Source

Try to avoid Project GUID conflicts.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2260 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
b74c496ea6
  1. 34
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
  2. 1
      src/Main/Base/Project/Src/Project/MissingProject.cs
  3. 2
      src/Main/Base/Project/Src/Project/Solution/AbstractSolutionFolder.cs
  4. 4
      src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs
  5. 1
      src/Main/Base/Project/Src/Project/UnknownProject.cs
  6. 8
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs
  7. 12
      src/Main/Base/Project/Src/Util/Linq.cs

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

@ -120,7 +120,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -120,7 +120,7 @@ namespace ICSharpCode.SharpDevelop.Project
Name = information.ProjectName;
FileName = information.OutputProjectFileName;
IdGuid = "{" + Guid.NewGuid().ToString().ToUpperInvariant() + "}";
base.IdGuid = "{" + Guid.NewGuid().ToString().ToUpperInvariant() + "}";
MSBuild.BuildPropertyGroup group = project.AddNewPropertyGroup(false);
group.AddNewProperty(ProjectGuidPropertyName, IdGuid, true);
group.AddNewProperty("Configuration", "Debug", true).Condition = " '$(Configuration)' == '' ";
@ -130,6 +130,15 @@ namespace ICSharpCode.SharpDevelop.Project @@ -130,6 +130,15 @@ namespace ICSharpCode.SharpDevelop.Project
this.ActivePlatform = "AnyCPU";
}
/// <summary>
/// The MSBuild property used to store the project's IdGuid.
/// The IdGuid is only stored in the project file to make multiple solutions use the same
/// GUID for the project when the project is added to multiple solutions. However, the actual
/// GUID used for the project in the solution can differ from the GUID in the project file -
/// SharpDevelop does not try to correct mismatches but simply always use the value from the solution.
/// SharpDevelop creates a new GUID for the solution when the project GUID cannot be used because it
/// would conflict with another project. This happens when one project is created by copying another project.
/// </summary>
public const string ProjectGuidPropertyName = "ProjectGuid";
/// <summary>
@ -849,18 +858,25 @@ namespace ICSharpCode.SharpDevelop.Project @@ -849,18 +858,25 @@ namespace ICSharpCode.SharpDevelop.Project
CreateItemsListFromMSBuild();
LoadConfigurationPlatformNamesFromMSBuild();
IdGuid = GetEvaluatedProperty(ProjectGuidPropertyName);
if (IdGuid == null) {
// Fix projects that have nb GUID
IdGuid = Guid.NewGuid().ToString();
SetPropertyInternal(null, null, ProjectGuidPropertyName, IdGuid, PropertyStorageLocations.Base, true);
base.IdGuid = GetEvaluatedProperty(ProjectGuidPropertyName);
} finally {
isLoading = false;
}
}
[Browsable(false)]
public override string IdGuid {
get { return base.IdGuid; }
set {
if (base.IdGuid == null) {
// Save the GUID in the project if the project does not yet have a GUID.
SetPropertyInternal(null, null, ProjectGuidPropertyName, value, PropertyStorageLocations.Base, true);
try {
// save fixed project
project.Save(fileName);
project.Save(this.FileName);
} catch {}
}
} finally {
isLoading = false;
base.IdGuid = value;
}
}
#endregion

1
src/Main/Base/Project/Src/Project/MissingProject.cs

@ -15,7 +15,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -15,7 +15,6 @@ namespace ICSharpCode.SharpDevelop.Project
{
Name = title;
FileName = fileName;
IdGuid = "{" + Guid.NewGuid().ToString() + "}";
TypeGuid = "{00000000-0000-0000-0000-000000000000}";
}
}

2
src/Main/Base/Project/Src/Project/Solution/AbstractSolutionFolder.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -51,7 +51,7 @@ namespace ICSharpCode.SharpDevelop.Project
}
[Browsable(false)]
public string IdGuid {
public virtual string IdGuid {
get {
return idGuid;
}

4
src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs

@ -79,6 +79,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -79,6 +79,10 @@ namespace ICSharpCode.SharpDevelop.Project
public virtual void AddFolder(ISolutionFolder folder)
{
if (string.IsNullOrEmpty(folder.IdGuid)) {
folder.IdGuid = Guid.NewGuid().ToString().ToUpperInvariant();
}
if (folder.Parent != null) {
folder.Parent.RemoveFolder(folder);
}

1
src/Main/Base/Project/Src/Project/UnknownProject.cs

@ -44,7 +44,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -44,7 +44,6 @@ namespace ICSharpCode.SharpDevelop.Project
{
Name = title;
FileName = fileName;
IdGuid = "{" + Guid.NewGuid().ToString() + "}";
TypeGuid = "{00000000-0000-0000-0000-000000000000}";
}
}

8
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -196,6 +196,14 @@ namespace ICSharpCode.SharpDevelop.Project @@ -196,6 +196,14 @@ namespace ICSharpCode.SharpDevelop.Project
public static void AddProject(ISolutionFolderNode solutionFolderNode, IProject newProject)
{
if (Linq.Exists(solutionFolderNode.Solution.SolutionFolders,
delegate (ISolutionFolder folder) {
return string.Equals(folder.IdGuid, newProject.IdGuid, StringComparison.OrdinalIgnoreCase);
}))
{
LoggingService.Warn("ProjectService.AddProject: Duplicate IdGuid detected");
newProject.IdGuid = Guid.NewGuid().ToString().ToUpperInvariant();
}
solutionFolderNode.Container.AddFolder(newProject);
ParserService.CreateProjectContentForAddedProject(newProject);
solutionFolderNode.Solution.FixSolutionConfiguration(new IProject[] { newProject });

12
src/Main/Base/Project/Src/Util/Linq.cs

@ -75,6 +75,18 @@ namespace ICSharpCode.SharpDevelop @@ -75,6 +75,18 @@ namespace ICSharpCode.SharpDevelop
return default(T);
}
/// <summary>
/// Gets if any element in the input matches the filter.
/// </summary>
public static bool Exists<T>(IEnumerable<T> input, Predicate<T> filter)
{
foreach (T element in input) {
if (filter(element))
return true;
}
return false;
}
public static List<T> ToList<T>(IEnumerable<T> input)
{
return new List<T>(input);

Loading…
Cancel
Save