Today, during the development process, the version number of the software was found to be incorrect. Today, during the development process, the version number of the software was found to be incorrect.
Today, during the development process, the version number of the software was found to be incorrect.
Analysis later shows that the call is
var a = Application.ProductVersion;
Copy the code
This was possible, because start project is the project, the startup project changed, on the basis of the original added A project, equivalent to B project called A program, that lead to the Application. The ProductVersion B is to read the version number of the project, to obtain the version number is 1.0.0, So you can only change the method of obtaining the version number.
The method to get the assembly is found later
var b = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
Copy the code
This gets the version of the assembly, but if the version number is preceded by a 0, it is omitted
For example, if the version number is 1.10.30.0611, and the reading process is 1.10.30.611 using the above method, it obviously does not meet the requirements
Then I found another method
var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
var c = System.Diagnostics.FileVersionInfo.GetVersionInfo(assemblyLocation).FileVersion;
Copy the code
This method is to get the assembly location, and then to get its file version number, but it is also possible to get the assembly ProductVersion.