|
1 | 1 | using System.Collections.Generic;
|
2 | 2 | using System.IO;
|
3 |
| -using System.Linq; |
4 | 3 | using System.Text.RegularExpressions;
|
5 |
| -using HtmlAgilityPack; |
| 4 | +using System.Xml; |
6 | 5 | using Volo.Abp.Cli.ProjectBuilding.Files;
|
7 | 6 |
|
8 | 7 | namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
|
@@ -49,51 +48,43 @@ private string ProcessFileContent(string content)
|
49 | 48 | {
|
50 | 49 | Check.NotNull(content, nameof(content));
|
51 | 50 |
|
52 |
| - var doc = new HtmlDocument(); |
| 51 | + var doc = new XmlDocument() { PreserveWhitespace = true }; |
53 | 52 |
|
54 | 53 | doc.Load(GenerateStreamFromString(content));
|
55 | 54 |
|
56 |
| - var nodes = doc.DocumentNode.SelectNodes("//projectreference[@include]"); |
57 |
| - |
58 |
| - if (nodes == null) |
59 |
| - { |
60 |
| - return content; |
61 |
| - } |
62 |
| - |
63 |
| - return ProcessReferenceNodes(nodes, content); |
| 55 | + return ProcessReferenceNodes(doc, content); |
64 | 56 | }
|
65 | 57 |
|
66 |
| - private string ProcessReferenceNodes(HtmlNodeCollection nodes, string content) |
| 58 | + private string ProcessReferenceNodes(XmlDocument doc, string content) |
67 | 59 | {
|
68 |
| - Check.NotNull(nodes, nameof(nodes)); |
69 | 60 | Check.NotNull(content, nameof(content));
|
70 | 61 |
|
71 |
| - foreach (var node in nodes) |
| 62 | + var nodes = doc.SelectNodes("/Project/ItemGroup/ProjectReference[@Include]"); |
| 63 | + |
| 64 | + foreach (XmlNode node in nodes) |
72 | 65 | {
|
73 |
| - var valueAttr = node.Attributes.FirstOrDefault(a => a.Name.ToLower() == "include"); |
| 66 | + var valueAttr = node.Attributes["Include"]; |
74 | 67 |
|
75 | 68 | // ReSharper disable once PossibleNullReferenceException : Can not be null because nodes are selected with include attribute filter in previous method
|
76 | 69 | if (valueAttr.Value.Contains($"{_companyNamePlaceHolder}.{_projectNamePlaceHolder}"))
|
77 | 70 | {
|
78 | 71 | continue;
|
79 | 72 | }
|
80 | 73 |
|
81 |
| - var newValue = ConvertToNugetReference(valueAttr.Value); |
| 74 | + valueAttr.Value = ConvertToNugetReference(valueAttr.Value); |
82 | 75 |
|
83 |
| - var oldLine = $"<ProjectReference Include=\"{valueAttr.Value}\""; |
84 |
| - var oldLineAlt = $"<ProjectReference Include=\"{valueAttr.Value}\""; |
85 |
| - var newLine = $"<PackageReference Include=\"{newValue}\" Version=\"{_latestNugetPackageVersion}\""; |
| 76 | + var versionAttr = doc.CreateAttribute("Version"); |
| 77 | + versionAttr.Value = _latestNugetPackageVersion; |
86 | 78 |
|
87 |
| - content = content.Replace(oldLine, newLine); |
88 |
| - content = content.Replace(oldLineAlt, newLine); |
| 79 | + node.Attributes.Append(versionAttr); |
89 | 80 | }
|
90 | 81 |
|
91 |
| - return content; |
| 82 | + return doc.OuterXml; |
92 | 83 | }
|
93 | 84 |
|
94 | 85 | private string ConvertToNugetReference(string oldValue)
|
95 | 86 | {
|
96 |
| - var newValue = Regex.Match(oldValue, @"\\((?!.+?\\).+?)\.csproj"); |
| 87 | + var newValue = Regex.Match(oldValue, @"\\((?!.+?\\).+?)\.csproj", RegexOptions.CultureInvariant | RegexOptions.Compiled); |
97 | 88 | if (newValue.Success && newValue.Groups.Count == 2)
|
98 | 89 | {
|
99 | 90 | return newValue.Groups[1].Value;
|
|
0 commit comments