From f1b4b1a200ada5899df608c0745aa01643aad70a Mon Sep 17 00:00:00 2001 From: samatrhea Date: Mon, 27 Feb 2023 21:09:30 +0100 Subject: [PATCH] [Fix] null reference exception when processing version of PackageReferences --- .../NetProjectPackageExtractor.csproj | 2 +- .../Services/ProjectFileParser.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/NetProjectPackageExtractor/NetProjectPackageExtractor.csproj b/NetProjectPackageExtractor/NetProjectPackageExtractor.csproj index 16d24eb..6a815a7 100644 --- a/NetProjectPackageExtractor/NetProjectPackageExtractor.csproj +++ b/NetProjectPackageExtractor/NetProjectPackageExtractor.csproj @@ -9,7 +9,7 @@ nppe nppe ./nupkg - 1.0.0 + 1.0.1 disable diff --git a/NetProjectPackageExtractor/Services/ProjectFileParser.cs b/NetProjectPackageExtractor/Services/ProjectFileParser.cs index 87997c1..b865960 100644 --- a/NetProjectPackageExtractor/Services/ProjectFileParser.cs +++ b/NetProjectPackageExtractor/Services/ProjectFileParser.cs @@ -89,20 +89,19 @@ private static IEnumerable ParseProjectFile(FileInfo projectFile) { projectVersion = versionElement.InnerText; } - - + var packageReferenceElements = document.GetElementsByTagName("PackageReference"); foreach (var element in packageReferenceElements) { var xmlElement = (XmlNode)element; - - var package = new Package + + var package = new Package { ProjectTitle = projectTitle, ProjectVersion = projectVersion, - Name = xmlElement.Attributes["Include"].Value, - Version = xmlElement.Attributes["Version"].Value, + Name = xmlElement.Attributes["Include"]?.Value, + Version = xmlElement.Attributes["Version"]?.Value, }; yield return package;