Home > Backend Development > C++ > How to Retrieve AssemblyVersion and AssemblyFileVersion in .NET?

How to Retrieve AssemblyVersion and AssemblyFileVersion in .NET?

Patricia Arquette
Release: 2024-12-31 06:14:09
Original
411 people have browsed it

How to Retrieve AssemblyVersion and AssemblyFileVersion in .NET?

Retrieving Assembly File Version from AssemblyInfo

The AssemblyInfo file defines two assembly versions: AssemblyVersion and AssemblyFileVersion. While AssemblyVersion specifies the attributed assembly version, AssemblyFileVersion instructs the compiler to use a particular version number for the Win32 file version resource, which may differ from the AssemblyVersion.

To retrieve the AssemblyVersion, you can use the code snippet:

Version version = Assembly.GetEntryAssembly().GetName().Version;
Copy after login

However, obtaining the AssemblyFileVersion requires a different approach. Here's how you can get it:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
Copy after login

This code fetches the active assembly, retrieves its file version information, and extracts the file version.

The above is the detailed content of How to Retrieve AssemblyVersion and AssemblyFileVersion in .NET?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template