Created
October 10, 2023 05:40
-
-
Save maliming/e82ad2fca317dd57799ae5f14221dc00 to your computer and use it in GitHub Desktop.
Update volo packages based on abp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Xml.Linq; | |
var abpPackages = new Dictionary<string, string>(); | |
var csprojFiles = Directory.GetFiles("C:\\Github\\Volosoft\\abp", "*.csproj", SearchOption.AllDirectories); | |
foreach (var csprojFile in csprojFiles) | |
{ | |
var csproj = XDocument.Load(csprojFile); | |
var packageReferences = csproj.Descendants().Where(x => x.Name.LocalName == "PackageReference"); | |
foreach (var packageReference in packageReferences) | |
{ | |
var include = packageReference.Attribute("Include"); | |
if (include == null) | |
{ | |
continue; | |
} | |
var version = packageReference.Attribute("Version"); | |
if (version == null || version.Value.Contains("$") || version.Value.Contains("8.0.0-rc.1.*")) | |
{ | |
continue; | |
} | |
var name = include.Value; | |
var ver = version.Value; | |
abpPackages.TryAdd(name, ver); | |
} | |
} | |
var voloCsprojFiles = Directory.GetFiles("C:\\Github\\Volosoft\\volo", "*.csproj", SearchOption.AllDirectories); | |
var notFoundPackages = new List<string>(); | |
foreach (var csprojFile in voloCsprojFiles) | |
{ | |
var fileLines = File.ReadAllLines(csprojFile); | |
var changed = false; | |
for (var i = 0; i < fileLines.Length; i++) | |
{ | |
var line = fileLines[i]; | |
if (line.Contains("<PackageReference") && !line.Contains("8.0.0-rc.1.*") && !line.Contains("Volo.Abp")) | |
{ | |
var packageName = Regex.Match(line, "Include=\"(.*?)\"").Groups[1].Value; | |
var packageVersion = Regex.Match(line, "Version=\"(.*?)\"").Groups[1].Value; | |
if (packageVersion.Contains("$")) | |
{ | |
continue; | |
} | |
if (abpPackages.TryGetValue(packageName, out var abpVersion)) | |
{ | |
if (abpVersion != packageVersion) | |
{ | |
fileLines[i] = line.Replace(packageVersion, abpVersion); | |
changed = true; | |
} | |
} | |
else | |
{ | |
notFoundPackages.Add(packageName); | |
} | |
} | |
} | |
if (changed) | |
{ | |
var str = string.Join(Environment.NewLine, fileLines); | |
if (!str.EndsWith( Environment.NewLine)) | |
{ | |
str += Environment.NewLine; | |
} | |
File.WriteAllText(csprojFile, str, Encoding.UTF8); | |
} | |
} | |
notFoundPackages = notFoundPackages.OrderBy(x => x).Distinct().ToList(); | |
Console.WriteLine("Not found packages:"); | |
Console.WriteLine(string.Join(Environment.NewLine, notFoundPackages)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment