Get version from non-executable file

I know how to get the version of an executable application or dll. However, I need to find the properties of a non-executing application.

I have a small program to set file associations for my main application. For users of older versions, there is no point, because the application does not accept arguments at startup. Therefore, when starting the file associator, it first checks to see if it can find the main application. If possible, I want to check the properties without executing it. If the version is earlier than one, which can take arguments, I want to inform my user about the need for updating, and not proceed with setting up the association.

I looked at System.IO.FileInfo, but it does not seem to contain any version information.

thanks

+6
source share
1 answer

You can use FileVersionInfo.GetVersionInfo() :

 FileVersionInfo vi = FileVersionInfo.GetVersionInfo("myfile.dll"); 

string showVersion = vi.FileVersion;

// showVersion is a valid version of No.

This returns file / document metadata and can be used for unmanaged DLLs or even text documents .

You can also use Assembly:

 Version v = Assembly.ReflectionOnlyLoadFrom("myfile.dll").GetName().Version; 

It will contain. NET version information .

+11
source

Source: https://habr.com/ru/post/887814/


All Articles