Skip to content

Commit 635d9b8

Browse files
ronaldbarendsebergmania
authored andcommitted
Use version of the assembly with the same name as the package ID (#16544)
(cherry picked from commit 14a0e62)
1 parent a76af1d commit 635d9b8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Reflection;
3+
using System.Runtime.Loader;
14
using System.Xml.Linq;
25
using Microsoft.Extensions.DependencyInjection;
36
using Microsoft.Extensions.FileProviders;
@@ -354,8 +357,16 @@ public async Task<IEnumerable<InstalledPackage>> GetAllInstalledPackagesAsync()
354357

355358
if (!string.IsNullOrEmpty(packageManifest.Version))
356359
{
360+
// Always use package version from manifest
357361
installedPackage.Version = packageManifest.Version;
358362
}
363+
else if (string.IsNullOrEmpty(installedPackage.Version) &&
364+
string.IsNullOrEmpty(installedPackage.PackageId) is false &&
365+
TryGetAssemblyInformationalVersion(installedPackage.PackageId, out string? version))
366+
{
367+
// Use version of the assembly with the same name as the package ID
368+
installedPackage.Version = version;
369+
}
359370
}
360371

361372
// Return all packages with an ID or name in the package manifest or package migrations
@@ -414,4 +425,20 @@ public Task<PagedModel<InstalledPackage>> GetInstalledPackagesFromMigrationPlans
414425

415426
return packageFile.CreateReadStream();
416427
}
428+
429+
private static bool TryGetAssemblyInformationalVersion(string name, [NotNullWhen(true)] out string? version)
430+
{
431+
foreach (Assembly assembly in AssemblyLoadContext.Default.Assemblies)
432+
{
433+
AssemblyName assemblyName = assembly.GetName();
434+
if (string.Equals(assemblyName.Name, name, StringComparison.OrdinalIgnoreCase) &&
435+
assembly.TryGetInformationalVersion(out version))
436+
{
437+
return true;
438+
}
439+
}
440+
441+
version = null;
442+
return false;
443+
}
417444
}

0 commit comments

Comments
 (0)