|
|
|
@ -1,8 +1,10 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Xml; |
|
|
|
using NuGet.Versioning; |
|
|
|
using NUglify.Helpers; |
|
|
|
using Volo.Abp.Cli.Utils; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
@ -10,13 +12,31 @@ namespace Volo.Abp.Cli.ProjectModification; |
|
|
|
|
|
|
|
public class SolutionPackageVersionFinder : ITransientDependency |
|
|
|
{ |
|
|
|
public string Find(string solutionFile, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX") |
|
|
|
public string FindByDllVersion(string solutionFile, string dllName = "Volo.Abp*") |
|
|
|
{ |
|
|
|
var projectFilesUnderSrc = GetProjectFilesOfSolution(solutionFile); |
|
|
|
foreach (var projectFile in projectFilesUnderSrc) |
|
|
|
{ |
|
|
|
var dllFiles = Directory.GetFiles(Path.GetDirectoryName(projectFile)!, $"{dllName}.dll", SearchOption.AllDirectories); |
|
|
|
|
|
|
|
if (dllFiles.Any()) |
|
|
|
{ |
|
|
|
var version = FileVersionInfo.GetVersionInfo(dllFiles.First()); |
|
|
|
|
|
|
|
return $"{version.FileMajorPart}.{version.FileMinorPart}.{version.FileBuildPart}"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public string FindByCsprojVersion(string solutionFile, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX", string includedKeyword = null) |
|
|
|
{ |
|
|
|
var projectFilesUnderSrc = GetProjectFilesOfSolution(solutionFile); |
|
|
|
foreach (var projectFile in projectFilesUnderSrc) |
|
|
|
{ |
|
|
|
var content = File.ReadAllText(projectFile); |
|
|
|
if (TryParseVersionFromCsprojViaXmlDocument(content, out var s, packagePrefix, excludedKeywords)) |
|
|
|
if (TryParseVersionFromCsprojViaXmlDocument(content, out var s, packagePrefix, excludedKeywords, includedKeyword)) |
|
|
|
{ |
|
|
|
return s; |
|
|
|
} |
|
|
|
@ -25,7 +45,7 @@ public class SolutionPackageVersionFinder : ITransientDependency |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private static bool TryParseVersionFromCsprojViaXmlDocument(string content, out string version, string packagePrefix, string excludedKeywords) |
|
|
|
private static bool TryParseVersionFromCsprojViaXmlDocument(string content, out string version, string packagePrefix, string excludedKeywords, string includedKeyword) |
|
|
|
{ |
|
|
|
var doc = new XmlDocument() { PreserveWhitespace = true }; |
|
|
|
using (var stream = StreamHelper.GenerateStreamFromString(content)) |
|
|
|
@ -39,7 +59,12 @@ public class SolutionPackageVersionFinder : ITransientDependency |
|
|
|
{ |
|
|
|
var packageId = node!.Attributes["Include"]?.Value; |
|
|
|
|
|
|
|
if (excludedKeywords.Split(',').Any(ek => packageId!.Contains(ek))) |
|
|
|
if (!excludedKeywords.IsNullOrWhiteSpace() && excludedKeywords.Split(',').Any(ek => packageId!.Contains(ek))) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!includedKeyword.IsNullOrWhiteSpace() && !packageId!.Contains(includedKeyword)) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
@ -65,17 +90,17 @@ public class SolutionPackageVersionFinder : ITransientDependency |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static bool TryParseVersionFromCsprojFile(string csprojContent, out string version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX") |
|
|
|
public static bool TryParseVersionFromCsprojFile(string csprojContent, out string version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX", string includedKeywords = null) |
|
|
|
{ |
|
|
|
return TryParseVersionFromCsprojViaXmlDocument(csprojContent, out version, packagePrefix, excludedKeywords); |
|
|
|
return TryParseVersionFromCsprojViaXmlDocument(csprojContent, out version, packagePrefix, excludedKeywords, includedKeywords); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool TryParseSemanticVersionFromCsprojFile(string csprojContent, out SemanticVersion version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX") |
|
|
|
public static bool TryParseSemanticVersionFromCsprojFile(string csprojContent, out SemanticVersion version, string packagePrefix = "Volo.Abp", string excludedKeywords = "LeptonX", string includedKeywords = null) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
if (TryParseVersionFromCsprojViaXmlDocument(csprojContent, out var versionText, packagePrefix, excludedKeywords)) |
|
|
|
if (TryParseVersionFromCsprojViaXmlDocument(csprojContent, out var versionText, packagePrefix, excludedKeywords, includedKeywords)) |
|
|
|
{ |
|
|
|
return SemanticVersion.TryParse(versionText, out version); |
|
|
|
} |
|
|
|
|