One small function of a large program examines assemblies in a folder and replaces out-of-date assemblies with the latest versions. To accomplish this, it needs to read the version numbers of the existing assembly files without actually loading those assemblies into the executing process.
If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there. In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.
The version number is stored in the assembly manifest along with other identity information, including the assembly name and public key, as well as information on relationships and identities of other assemblies connected with the application.
I can get the Assembly Version with the following line of code: Version version = Assembly.
It's the version number given to file as in file system. It's displayed by Windows Explorer, and never used by . NET framework or runtime for referencing.
I found the following in this article.
using System.Reflection; using System.IO; ... // 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; } // Update older version File.Copy(updatedAssemblyPath, currentAssemblyPath, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With