Skip to content

Commit

Permalink
Use version of the assembly with the same name as the package ID (#16544
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ronaldbarendse authored Sep 26, 2024
1 parent 609b5f7 commit 14a0e62
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.Loader;
using System.Xml.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
Expand Down Expand Up @@ -354,8 +357,16 @@ public async Task<IEnumerable<InstalledPackage>> GetAllInstalledPackagesAsync()

if (!string.IsNullOrEmpty(packageManifest.Version))
{
// Always use package version from manifest
installedPackage.Version = packageManifest.Version;
}
else if (string.IsNullOrEmpty(installedPackage.Version) &&
string.IsNullOrEmpty(installedPackage.PackageId) is false &&
TryGetAssemblyInformationalVersion(installedPackage.PackageId, out string? version))
{
// Use version of the assembly with the same name as the package ID
installedPackage.Version = version;
}
}

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

return packageFile.CreateReadStream();
}

private static bool TryGetAssemblyInformationalVersion(string name, [NotNullWhen(true)] out string? version)
{
foreach (Assembly assembly in AssemblyLoadContext.Default.Assemblies)
{
AssemblyName assemblyName = assembly.GetName();
if (string.Equals(assemblyName.Name, name, StringComparison.OrdinalIgnoreCase) &&
assembly.TryGetInformationalVersion(out version))
{
return true;
}
}

version = null;
return false;
}
}

0 comments on commit 14a0e62

Please sign in to comment.