Skip to content

Commit

Permalink
fix: Preventing crash when attempting to update versions set to variable
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrandolph committed May 13, 2024
1 parent b20016a commit 82c8320
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/NvGet/Tools/Updater/Extensions/XmlDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Linq;
using System.Xml;
using Newtonsoft.Json;
using NuGet.Common;
using NuGet.Versioning;
using NvGet.Entities;
using NvGet.Extensions;
using NvGet.Helpers;
using NvGet.Tools.Updater.Log;
Expand All @@ -20,6 +22,8 @@ namespace NvGet.Tools.Updater.Extensions
{
public static class XmlDocumentExtensions
{
public static ILogger Logger { get; set; } = ConsoleLogger.Instance;

/// <summary>
/// Runs an <see cref="UpdateOperation"/> on Project Properties contained in a <see cref="XmlDocument"/>.
/// </summary>
Expand All @@ -35,7 +39,7 @@ public static IEnumerable<UpdateOperation> UpdateUpdateProperties(

var packageId = operation.PackageId;

foreach(var prop in updateProperties.Where(x=> x.PackageId == packageId))
foreach(var prop in updateProperties.Where(x => x.PackageId == packageId))
{
var docProp = document.SelectElements(prop.PropertyName).FirstOrDefault();
if(docProp is null)
Expand Down Expand Up @@ -85,14 +89,21 @@ UpdateOperation operation

if(packageVersion.HasValue())
{
var currentOperation = operation.WithPreviousVersion(packageVersion);
try
{
var currentOperation = operation.WithPreviousVersion(packageVersion);

if(currentOperation.ShouldProceed())
if(currentOperation.ShouldProceed())
{
packageReference.SetAttributeOrChild("Version", currentOperation.UpdatedVersion.ToString());
}

operations.Add(currentOperation);
}
catch
{
packageReference.SetAttributeOrChild("Version", currentOperation.UpdatedVersion.ToString());
Logger.LogDebug($"Ignoring {packageReference.Name} as value is set to something other than a version (eg project variable)");
}

operations.Add(currentOperation);
}
}

Expand Down

0 comments on commit 82c8320

Please sign in to comment.