0

I'm trying to get the version from MSI/exe files.

Pic

enter image description here

I tried both exe and msi file but it returns as null.

var versionInfo = FileVersionInfo.GetVersionInfo(@"path\setup.exe");
            string version = versionInfo.FileVersion; 

I tried write the version in the description field and read it but again, it returns as null.

How can I get this field by code ?

Pradeep Kumar
  • 1,193
  • 1
  • 9
  • 21
Dan D
  • 11
  • 1
  • FileVersionInfo can only work on executable files that have a VERSIONINFO resource. For .msi files you need to use the MSI api. Project > Add Reference > Browse, select c:\windows\system32\msi.dll to start using the COM component. I think a version number is available from Document.SummaryInfo, "ProductVersion" property. – Hans Passant Dec 14 '22 at 17:54

1 Answers1

0

In Visual Studio, right click your project and go to Properties. From Properties go to Package->General and scroll down to find "File Version". Here you can set the File Version property of the file when it is compiled.

File Version

The code you provided can now retrieve the version!

Print File Version

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Ethan
  • 109
  • 1
  • 3
  • Seems OP has already tried this, since it's the same code in question. – Pac0 Dec 14 '22 at 22:43
  • OP set a property called "Version", In my answer I clearly state it's suppose to be the "File Version" for the method he is using. – Ethan Dec 15 '22 at 05:38