Cosmos project upgrader improvements.

This commit is contained in:
José Pedro 2017-12-27 18:17:01 +00:00
parent b7b020f575
commit ce20ebbf9a
No known key found for this signature in database
GPG key ID: B8247B9301707B83
2 changed files with 14 additions and 22 deletions

View file

@ -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()
{

View file

@ -7,10 +7,4 @@
<PropertyGroup>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cosmos.Build" Version="*" />
<PackageReference Include="Cosmos.Debug.Kernel" Version="*" />
<PackageReference Include="Cosmos.System2" Version="*" />
</ItemGroup>
</Project>