From ce20ebbf9a19f0bcb9decb051fd53d908dab2ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Wed, 27 Dec 2017 18:17:01 +0000 Subject: [PATCH] Cosmos project upgrader improvements. --- .../MigrateCosmosProjectFactory.cs | 30 +++++++++---------- .../ProjectTemplate.xml | 6 ---- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/source/Cosmos.VS.ProjectSystem/MigrateCosmosProjectFactory.cs b/source/Cosmos.VS.ProjectSystem/MigrateCosmosProjectFactory.cs index b8da1f66b..fcfe77256 100644 --- a/source/Cosmos.VS.ProjectSystem/MigrateCosmosProjectFactory.cs +++ b/source/Cosmos.VS.ProjectSystem/MigrateCosmosProjectFactory.cs @@ -203,24 +203,22 @@ namespace Cosmos.VS.ProjectSystem var document = XDocument.Load(codeProjectStream); var itemGroups = document.Root.Descendants().Where(e => e.Name == "ItemGroup"); - var projectReferences = itemGroups.Descendants().Where( - e => e.Name == "ProjectReference" && e.Attributes().Where( - a => a.Name == "Include" && - (a.Value.EndsWith("Cosmos.System.csproj") || a.Value.EndsWith("Cosmos.System2.csproj") - || a.Value.EndsWith("Cosmos.Debug.Kernel.csproj"))) - .Count() == 0); - var packageReferences = itemGroups.Descendants().Where( - e => e.Name == "PackageReference" && e.Attributes().Where( - a => a.Name == "Include" && - (a.Value == "Cosmos.System" || a.Value == "Cosmos.System2" || a.Value == "Cosmos.Debug.Kernel")) - .Count() == 0); var references = itemGroups.Descendants().Where(e => e.Name == "Reference"); + var projectReferences = itemGroups.Descendants().Where(e => e.Name == "ProjectReference"); + var packageReferences = itemGroups.Descendants().Where(e => e.Name == "PackageReference"); if (packageReferences.Any(p => p.Attributes().Any(a => a.Name == "Include" && a.Value == "Cosmos.Build"))) { return; } + var cosmosBuildPackageReference = new XElement("PackageReference"); + cosmosBuildPackageReference.Add(new XAttribute("Include", "Cosmos.Build")); + cosmosBuildPackageReference.Add(new XAttribute("Version", "*")); + + packageReferences.Append(cosmosBuildPackageReference); + packageReferences = packageReferences.OrderBy(p => p.Attributes().Where(a => a.Name == "Include").First().Value); + codeProjectStream.Dispose(); File.WriteAllText(codeProject, GetProjectTemplate()); @@ -230,6 +228,11 @@ namespace Cosmos.VS.ProjectSystem codeProjectDocument.Root.Descendants().Where(d => d.Name == "PropertyGroup").LastOrDefault() .Add(cosmosProjectProperties); + if (references.Count() > 0) + { + codeProjectDocument.Root.Add(new XElement("ItemGroup", references)); + } + if (projectReferences.Count() > 0) { codeProjectDocument.Root.Add(new XElement("ItemGroup", projectReferences)); @@ -240,11 +243,6 @@ namespace Cosmos.VS.ProjectSystem codeProjectDocument.Root.Add(new XElement("ItemGroup", packageReferences)); } - if (references.Count() > 0) - { - codeProjectDocument.Root.Add(new XElement("ItemGroup", references)); - } - using (var xmlWriter = XmlWriter.Create(codeProject, new XmlWriterSettings() { diff --git a/source/Cosmos.VS.ProjectSystem/ProjectTemplate.xml b/source/Cosmos.VS.ProjectSystem/ProjectTemplate.xml index b80271207..f59b9d7b0 100644 --- a/source/Cosmos.VS.ProjectSystem/ProjectTemplate.xml +++ b/source/Cosmos.VS.ProjectSystem/ProjectTemplate.xml @@ -7,10 +7,4 @@ - - - - - -