diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs
index 993c79f9b5..6de83c39f5 100644
--- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs
+++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs
@@ -1019,6 +1019,224 @@ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
);
}
+ [Fact]
+ public async Task UpdateBindingRedirect_UnrelatedAssemblyReferenceWithMissingPublicKeyTokenAttribute()
+ {
+ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
+ packages:
+ [
+ MockNuGetPackage.CreatePackageWithAssembly("Some.Package", "7.0.1", "net45", "7.0.0.0"),
+ MockNuGetPackage.CreatePackageWithAssembly("Some.Package", "13.0.1", "net45", "13.0.0.0"),
+ ],
+ projectContents: """
+
+
+
+ v4.5
+
+
+
+
+
+
+
+
+
+ packages\Some.Package.7.0.1\lib\net45\Some.Package.dll
+ True
+
+
+ packages\Some.Unrelated.Package.1.0.0\lib\net45\Some.Unrelated.Package.dll
+
+
+
+
+ """,
+ packagesConfigContents: """
+
+
+
+ """,
+ additionalFiles:
+ [
+ ("app.config", """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """)
+ ],
+ expectedProjectContents: """
+
+
+
+ v4.5
+
+
+
+
+
+
+
+
+
+ packages\Some.Package.13.0.1\lib\net45\Some.Package.dll
+ True
+
+
+ packages\Some.Unrelated.Package.1.0.0\lib\net45\Some.Unrelated.Package.dll
+
+
+
+
+ """,
+ expectedPackagesConfigContents: """
+
+
+
+
+ """,
+ additionalFilesExpected:
+ [
+ ("app.config", """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """)
+ ]
+ );
+ }
+
+ [Fact]
+ public async Task UpdateBindingRedirect_UnrelatedAssemblyReferenceWithMissingCultureAttribute()
+ {
+ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
+ packages:
+ [
+ MockNuGetPackage.CreatePackageWithAssembly("Some.Package", "7.0.1", "net45", "7.0.0.0"),
+ MockNuGetPackage.CreatePackageWithAssembly("Some.Package", "13.0.1", "net45", "13.0.0.0"),
+ ],
+ projectContents: """
+
+
+
+ v4.5
+
+
+
+
+
+
+
+
+
+ packages\Some.Package.7.0.1\lib\net45\Some.Package.dll
+ True
+
+
+ packages\Some.Unrelated.Package.1.0.0\lib\net45\Some.Unrelated.Package.dll
+
+
+
+
+ """,
+ packagesConfigContents: """
+
+
+
+ """,
+ additionalFiles:
+ [
+ ("app.config", """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """)
+ ],
+ expectedProjectContents: """
+
+
+
+ v4.5
+
+
+
+
+
+
+
+
+
+ packages\Some.Package.13.0.1\lib\net45\Some.Package.dll
+ True
+
+
+ packages\Some.Unrelated.Package.1.0.0\lib\net45\Some.Unrelated.Package.dll
+
+
+
+
+ """,
+ expectedPackagesConfigContents: """
+
+
+
+
+ """,
+ additionalFilesExpected:
+ [
+ ("app.config", """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """)
+ ]
+ );
+ }
+
[Fact]
public async Task UpdateBindingRedirect_DuplicateRedirectsForTheSameAssemblyAreRemoved()
{
diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs
index 2b6011c991..f156e1506c 100644
--- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs
+++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs
@@ -304,12 +304,12 @@ internal sealed class AssemblyIdentityIgnoreCaseComparer : IEqualityComparer
string.Equals(x?.Name, y?.Name, StringComparison.OrdinalIgnoreCase) &&
- string.Equals(x?.PublicKeyToken, y?.PublicKeyToken, StringComparison.OrdinalIgnoreCase);
+ string.Equals(x?.PublicKeyToken ?? "null", y?.PublicKeyToken ?? "null", StringComparison.OrdinalIgnoreCase);
public int GetHashCode(AssemblyIdentity obj) =>
HashCode.Combine(
obj.Name?.ToLowerInvariant(),
- obj.PublicKeyToken?.ToLowerInvariant()
+ obj.PublicKeyToken?.ToLowerInvariant() ?? "null"
);
}
}
diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs
index 29bdf75dbe..d838a3fd71 100644
--- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs
+++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs
@@ -48,8 +48,8 @@ static bool TryParseIncludesString(string include, [NotNullWhen(true)] out Assem
return false;
}
- dict.TryGetValue("PublicKeyToken", out var publicKeyToken);
- dict.TryGetValue("Culture", out var culture);
+ var publicKeyToken = dict.GetValueOrDefault("PublicKeyToken", "null");
+ var culture = dict.GetValueOrDefault("Culture", "neutral");
assemblyInfo = new AssemblyWrapper(name, version, publicKeyToken, culture);
return true;
@@ -63,7 +63,7 @@ static bool TryParseIncludesString(string include, [NotNullWhen(true)] out Assem
///
private class AssemblyWrapper : Runtime_IAssembly
{
- public AssemblyWrapper(string name, Version version, string? publicKeyToken = null, string? culture = null)
+ public AssemblyWrapper(string name, Version version, string publicKeyToken, string culture)
{
Name = name;
Version = version;
@@ -73,8 +73,8 @@ public AssemblyWrapper(string name, Version version, string? publicKeyToken = nu
public string Name { get; }
public Version Version { get; }
- public string? PublicKeyToken { get; }
- public string? Culture { get; }
+ public string PublicKeyToken { get; }
+ public string Culture { get; }
public IEnumerable ReferencedAssemblies { get; } = Enumerable.Empty();
}