Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Crash on Version and when version set to msbuild property #73

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/NvGet/Extensions/XmlDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public static PackageIdentity[] GetPackageReferences(this XmlDocument document)
var propertyGroupVersionReferences = document
.SelectElements("PropertyGroup")
.SelectMany(pg => pg.SelectNodes("*").OfType<XmlElement>())
.Where(e => e.LocalName.EndsWith("Version", StringComparison.OrdinalIgnoreCase));
.Where(e => e.LocalName.EndsWith("Version", StringComparison.OrdinalIgnoreCase) &&
!e.LocalName.StartsWith("Version", StringComparison.OrdinalIgnoreCase));

foreach(var versionProperty in propertyGroupVersionReferences)
{
Expand Down
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
Loading