diff --git a/CentralisedPackageConverter/PackageConverter.cs b/CentralisedPackageConverter/PackageConverter.cs index 370117f..431952a 100644 --- a/CentralisedPackageConverter/PackageConverter.cs +++ b/CentralisedPackageConverter/PackageConverter.cs @@ -108,7 +108,14 @@ private void RevertProject(FileInfo project, bool dryRun, Encoding encoding, str if( packageReference.Parent is not null ) { var condition = GetAttributeValue( packageReference.Parent, "Condition" ) ?? string.Empty; - var package = GetAttributeValue( packageReference, "Include" ); + if (!TryGetAttributeValue(packageReference, "Include", out var package)) + { + if (!TryGetAttributeValue(packageReference, "Update", out package)) + { + Console.WriteLine("Package reference has no Include or Update attribute. Skipping..."); + continue; + } + } if( this.referencesByConditionThenName.TryGetValue( condition, out var packagesByName ) ) { @@ -244,6 +251,22 @@ private IEnumerable GetDescendants(XDocument xml, string name) return attr?.Value; } + /// + /// Try to get an attribute value from an XML Element + /// + /// XML element. If null, result is false. + /// Attribute name, checked namespce- and case-insensitive (pick first) + /// The attribute value. + /// Boolean whether attribute was picked + private static bool TryGetAttributeValue(XElement? elem, string name, out string? value) + { + var attr = elem?.Attributes().FirstOrDefault(x => + string.Equals(x.Name.LocalName, name, StringComparison.OrdinalIgnoreCase)); + + value = attr?.Value; + return value != null; + } + /// /// Safely delete attributes with a name. ///