diff options
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
4 files changed, 43 insertions, 13 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildElement.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildElement.cs index dd18b5dd6a..b3e83ecec3 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildElement.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildElement.cs @@ -30,7 +30,7 @@ namespace MonoDevelop.Projects.MSBuild { string condition; - static readonly string [] knownAttributes = { "Condition", "Label" }; + static readonly string [] knownAttributes = { "Label", "Condition" }; internal override string [] GetKnownAttributes () { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildImport.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildImport.cs index 4115627e2f..bc821dad2e 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildImport.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildImport.cs @@ -33,7 +33,7 @@ namespace MonoDevelop.Projects.MSBuild { string target; - static readonly string [] knownAttributes = { "Project", "Condition", "Label" }; + static readonly string [] knownAttributes = { "Project", "Label", "Condition" }; internal override string [] GetKnownAttributes () { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs index ca174faa65..6c2dc55ffc 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs @@ -59,6 +59,27 @@ namespace MonoDevelop.Projects.SharedAssetsProjects languageName = language; } + protected override void OnNameChanged (SolutionItemRenamedEventArgs e) + { + if (!projItemsPath.IsNullOrEmpty && Path.GetFileNameWithoutExtension (e.OldName) == projItemsPath.FileNameWithoutExtension) { + // We are going to rename the projitems file, but before that, let's get all referencing projects, since they reference + // using the old path + string oldPath = ProjItemsPath; + var refProjects = GetReferencingProjects ().ToArray (); + + // Set the new projitems file name + projItemsPath = projItemsPath.ParentDirectory.Combine (e.NewName) + projItemsPath.Extension; + + // Update all referencing projects + foreach (var p in refProjects) { + var sr = p.References.FirstOrDefault (r => r.GetItemsProjectPath () == oldPath); + if (sr != null) + sr.SetItemsProjectPath (ProjItemsPath); + } + } + base.OnNameChanged (e); + } + protected override void OnInitializeFromTemplate (ProjectCreateInformation projectCreateInfo, XmlElement projectOptions) { base.OnInitializeFromTemplate (projectCreateInfo, projectOptions); @@ -135,7 +156,7 @@ namespace MonoDevelop.Projects.SharedAssetsProjects base.OnWriteProject (monitor, msproject); - var newProject = FileName == null || !File.Exists (FileName); + var newProject = FileName == null || projitemsProject.IsNewProject; if (newProject) { var grp = msproject.GetGlobalPropertyGroup (); if (grp == null) @@ -145,7 +166,7 @@ namespace MonoDevelop.Projects.SharedAssetsProjects import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"; msproject.AddNewImport (@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"); msproject.AddNewImport (@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props"); - import = msproject.AddNewImport (Path.ChangeExtension (FileName.FileName, ".projitems")); + import = msproject.AddNewImport (MSBuildProjectService.ToMSBuildPath (FileName.ParentDirectory, projItemsPath)); import.Label = "Shared"; if (LanguageName.Equals("C#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport (CSharptargets); @@ -155,7 +176,13 @@ namespace MonoDevelop.Projects.SharedAssetsProjects } } else { - msproject.Load (FileName); + var itemsImport = msproject.Imports.FirstOrDefault (i => i.Label == "Shared"); + if (itemsImport != null) + itemsImport.Project = MSBuildProjectService.ToMSBuildPath (FileName.ParentDirectory, projItemsPath); + else { + var import = msproject.AddNewImport (MSBuildProjectService.ToMSBuildPath (FileName.ParentDirectory, projItemsPath)); + import.Label = "Shared"; + } } // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly @@ -412,7 +439,7 @@ namespace MonoDevelop.Projects.SharedAssetsProjects if (ParentSolution == null) return new DotNetProject[0]; - return ParentSolution.GetAllItems<DotNetProject> ().Where (p => p.References.Any (r => r.GetItemsProjectPath () != null)); + return ParentSolution.GetAllItems<DotNetProject> ().Where (p => p.References.Any (r => r.GetItemsProjectPath () == ProjItemsPath)); } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildExtension.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildExtension.cs index b2c68ad756..1f5f652c87 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildExtension.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildExtension.cs @@ -71,13 +71,16 @@ namespace MonoDevelop.Projects.SharedAssetsProjects ip = MSBuildProjectService.ToMSBuildPath (Project.ItemDirectory, ip); validProjitems.Add (ip); if (!project.Imports.Any (im => im.Project == ip)) { - var fsharpProject = project.ProjectTypeGuids.Contains("{F2A71F9B-5D33-465A-A702-920D77279786}"); - MSBuildObject before; - if (fsharpProject) - //For F# use the first item group as the shared project files have to be listed first - before = project.ItemGroups.FirstOrDefault (i => i.Label != "Shared"); - else - before = project.Imports.FirstOrDefault (i => i.Label != "Shared"); + // If there is already a Shared import, place the new import in the same location + MSBuildObject before = project.Imports.FirstOrDefault (i => i.Label == "Shared" && i.Project.EndsWith (".projitems")); + if (before == null) { + var fsharpProject = project.ProjectTypeGuids.Contains("{F2A71F9B-5D33-465A-A702-920D77279786}"); + if (fsharpProject) + //For F# use the first item group as the shared project files have to be listed first + before = project.ItemGroups.FirstOrDefault (i => i.Label != "Shared"); + else + before = project.Imports.FirstOrDefault (i => i.Label != "Shared"); + } var im = project.AddNewImport (ip, beforeObject: before); im.Label = "Shared"; |