Created
March 27, 2024 13:51
-
-
Save NatMarchand/28ef46268de94048b177a3c1f6b4197b to your computer and use it in GitHub Desktop.
GlobalPackageReference
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
var path = @""; | |
var allVersions = new Dictionary<string, HashSet<string>>(); | |
foreach (var file in Directory.EnumerateFiles(path, "*.*proj", SearchOption.AllDirectories)) | |
{ | |
var doc = XDocument.Load(file); | |
bool hasChanges = false; | |
foreach (var reference in doc.XPathSelectElements("//PackageReference")) | |
{ | |
hasChanges = true; | |
var package = reference.Attribute("Include").Value; | |
var versions = allVersions.GetValueOrDefault(package, new HashSet<string>()); | |
var versionAttribute = reference.Attribute("Version"); | |
versions.Add(versionAttribute.Value); | |
allVersions[package] = versions; | |
versionAttribute.Remove(); | |
} | |
if (hasChanges) | |
{ | |
File.WriteAllText(file, doc.ToString()); | |
} | |
} | |
Console.WriteLine( | |
string.Join(Environment.NewLine, | |
allVersions.ToDictionary(v => v.Key, v => v.Value.OrderDescending().First()) | |
.OrderBy(v => v.Key) | |
.Select(v => $"<PackageVersion Include=\"{v.Key}\" Version=\"{v.Value}\" />"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment