Search code examples
c#arraysfileversion

How can I get the FileVersion information of an executable stored in memory as an array of bytes?


I need to read the FileVersion of an executable. The problem is that I don't have an actual file on disk, only an array of bytes. The FileVersion API only has a GetVersionInfo(string fileName) method, it doesn't have any method to grab the version from the file.

I tried looking into the source with a decompiler, but it looks more complicated than what a simple copy/paste can do.

Is there any way to read the FileVersion of a file, given that I have the bytes of file contents, without writing the file to disk?


Solution

  • Unfortunately, after lots of digging, and looking into the .NET Core source, available Javascript libraries, etc. I decided that this is not easy (or at all) possible and not worth the pain to figure out.

    Instead, I went with the simpler approach of:

    • Write the file to disk in some sort of temporary location
    • Read the version from the file on disk
    • Delete the file

    The code is simple and straight-forward .NET code, no fancy tricks or complicated JS libraries required.