Skip to content

Commit a8b035f

Browse files
MartyMcFlayeArnaud Lacroix
andauthored
fix(central-package-management): compare version ignoring casing
Co-authored-by: Arnaud Lacroix <[email protected]>
1 parent d5e69ac commit a8b035f

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/DotnetAffected.Core/NugetHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DotnetAffected.Abstractions;
22
using Microsoft.Build.Construction;
33
using Microsoft.Build.Evaluation;
4+
using System;
45
using System.Collections.Generic;
56
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
@@ -43,7 +44,7 @@ public static PackageRef Create(ProjectItem item, string? versionOverride = null
4344
}.Concat(conditions);
4445
}
4546

46-
var version = versionOverride ?? item.Metadata.Single(m => m.Name == "Version")
47+
var version = versionOverride ?? item.Metadata.Single(m => m.Name.Equals("Version", StringComparison.InvariantCultureIgnoreCase))
4748
.EvaluatedValue;
4849

4950
return new PackageRef(
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using DotnetAffected.Testing.Utils;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using Xunit;
5+
6+
namespace DotnetAffected.Core.Tests
7+
{
8+
/// <summary>
9+
///
10+
/// </summary>
11+
public class NugetHelperTests : BaseDotnetAffectedTest
12+
{
13+
[Fact]
14+
public async Task When_Version_Attribute_Casing_Is_Not_Standard_Using_Central_Management_Package_Should_Not_Throw()
15+
{
16+
// Create a Directory.Packages.props file with non standard casing for "Version" attribute
17+
var propsFile = @"
18+
<Project>
19+
<PropertyGroup>
20+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<PackageVersion Include=""Some.Library"" version=""5.0.0"" />
24+
</ItemGroup>
25+
</Project>
26+
";
27+
var propsPath = Path.Combine(Repository.Path, "Directory.Packages.props");
28+
await Repository.CreateTextFileAsync(propsPath, propsFile);
29+
30+
// Create a project with a nuget dependency
31+
const string projectName = "InventoryManagement";
32+
Repository.CreateCsProject(
33+
projectName,
34+
b => b.AddNuGetDependency("Some.Library"));
35+
36+
// Commit all so there are no changes
37+
Repository.StageAndCommit();
38+
39+
// update Directory.Packages.props file
40+
propsFile = @"
41+
<Project>
42+
<PropertyGroup>
43+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44+
</PropertyGroup>
45+
<ItemGroup>
46+
<PackageVersion Include=""Some.Library"" version=""6.0.0"" />
47+
</ItemGroup>
48+
</Project>
49+
";
50+
await Repository.CreateTextFileAsync(propsPath, propsFile);
51+
52+
// Verify that affected does not throw
53+
var exception = Record.Exception(() => AffectedSummary);
54+
Assert.Null(exception);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)