2

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 ?

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. Commented Dec 14, 2022 at 17:54

1 Answer 1

-1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Seems OP has already tried this, since it's the same code in question.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.