Loading ...

ASP.NET: How to get assembly version without loading it | CodeAsp.Net

ASP.NET: How to get assembly version without loading it

 /5
0 (0votes)

You all might be familiar with Assembly.LoadFrom method which can be use to get the version of the assembly but this method has a disadvantage as it will load the assembly into the domain and you will not be able to update that assembly after loading the assembly until the current app domain is unloaded. The solution is to use 
AssemblyName.GetAssemblyName. This method causes the file to be opened and closed, but the assembly is not added to this domain.

Example:

// Get current and updated assemblies
AssemblyName currentAssemblyName = AssemblyName.GetAssemblyName(currentAssemblyPath);
AssemblyName updatedAssemblyName = AssemblyName.GetAssemblyName(updatedAssemblyPath);

// Compare both versions
if (updatedAssemblyName.Version.CompareTo(currentAssemblyName.Version) <= 0)
{
    // There's nothing to update
    return;
}

Comments (no comments yet)

Top Posts