|
|
|
@ -1,8 +1,7 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using HtmlAgilityPack; |
|
|
|
using System.Xml; |
|
|
|
using Volo.Abp.Cli.ProjectBuilding.Files; |
|
|
|
|
|
|
|
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|
|
|
@ -49,28 +48,22 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|
|
|
{ |
|
|
|
Check.NotNull(content, nameof(content)); |
|
|
|
|
|
|
|
var doc = new HtmlDocument(); |
|
|
|
var doc = new XmlDocument() { PreserveWhitespace = true }; |
|
|
|
|
|
|
|
doc.Load(GenerateStreamFromString(content)); |
|
|
|
|
|
|
|
var nodes = doc.DocumentNode.SelectNodes("//projectreference[@include]"); |
|
|
|
|
|
|
|
if (nodes == null) |
|
|
|
{ |
|
|
|
return content; |
|
|
|
} |
|
|
|
|
|
|
|
return ProcessReferenceNodes(nodes, content); |
|
|
|
return ProcessReferenceNodes(doc, content); |
|
|
|
} |
|
|
|
|
|
|
|
private string ProcessReferenceNodes(HtmlNodeCollection nodes, string content) |
|
|
|
private string ProcessReferenceNodes(XmlDocument doc, string content) |
|
|
|
{ |
|
|
|
Check.NotNull(nodes, nameof(nodes)); |
|
|
|
Check.NotNull(content, nameof(content)); |
|
|
|
|
|
|
|
foreach (var node in nodes) |
|
|
|
var nodes = doc.SelectNodes("/Project/ItemGroup/ProjectReference[@Include]"); |
|
|
|
|
|
|
|
foreach (XmlNode node in nodes) |
|
|
|
{ |
|
|
|
var valueAttr = node.Attributes.FirstOrDefault(a => a.Name.ToLower() == "include"); |
|
|
|
var valueAttr = node.Attributes["Include"]; |
|
|
|
|
|
|
|
// ReSharper disable once PossibleNullReferenceException : Can not be null because nodes are selected with include attribute filter in previous method
|
|
|
|
if (valueAttr.Value.Contains($"{_companyNamePlaceHolder}.{_projectNamePlaceHolder}")) |
|
|
|
@ -78,22 +71,20 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
var newValue = ConvertToNugetReference(valueAttr.Value); |
|
|
|
valueAttr.Value = ConvertToNugetReference(valueAttr.Value); |
|
|
|
|
|
|
|
var oldLine = $"<ProjectReference Include=\"{valueAttr.Value}\""; |
|
|
|
var oldLineAlt = $"<ProjectReference Include=\"{valueAttr.Value}\""; |
|
|
|
var newLine = $"<PackageReference Include=\"{newValue}\" Version=\"{_latestNugetPackageVersion}\""; |
|
|
|
var versionAttr = doc.CreateAttribute("Version"); |
|
|
|
versionAttr.Value = _latestNugetPackageVersion; |
|
|
|
|
|
|
|
content = content.Replace(oldLine, newLine); |
|
|
|
content = content.Replace(oldLineAlt, newLine); |
|
|
|
node.Attributes.Append(versionAttr); |
|
|
|
} |
|
|
|
|
|
|
|
return content; |
|
|
|
return doc.OuterXml; |
|
|
|
} |
|
|
|
|
|
|
|
private string ConvertToNugetReference(string oldValue) |
|
|
|
{ |
|
|
|
var newValue = Regex.Match(oldValue, @"\\((?!.+?\\).+?)\.csproj"); |
|
|
|
var newValue = Regex.Match(oldValue, @"\\((?!.+?\\).+?)\.csproj", RegexOptions.CultureInvariant | RegexOptions.Compiled); |
|
|
|
if (newValue.Success && newValue.Groups.Count == 2) |
|
|
|
{ |
|
|
|
return newValue.Groups[1].Value; |
|
|
|
|