josephspurrier / goversioninfo

Golang Microsoft Windows File Properties/Version Info and Icon Resource Generator
MIT License
836 stars 115 forks source link

File version property always 0.0.0.0 when using StringFileInfo FileVersion #26

Closed X-Guardian closed 4 years ago

X-Guardian commented 6 years ago

Hi @josephspurrier,

I'm trying to set the File version property using the StringFileInfo FileVersion setting, but the property in the executable always has a value of 0.0.0.0.

I also get the same result if I use the file-version command-line flag.

Example versioninfo.json:

{
    "StringFileInfo": {
        "FileDescription": "FileDescription",
        "FileVersion": "1.0.0.0",
        "ProductName": "ProductName",
        "ProductVersion": "1.0.0.0",
        "LegalCopyright": "Copyright"
    }
}

image

hymkor commented 6 years ago

Property may show FixedFileInfo.FileVersion.

X-Guardian commented 6 years ago

Hi @zetamatta, my versioninfo.json doesn't have the FixedFileInfo section.

hymkor commented 6 years ago

My json as sample .

{
    "FixedFileInfo":
    {
        "FileVersion": {
            "Major": 4,
            "Minor": 2,
            "Patch": 0,
            "Build": 5
        },
        "ProductVersion": {
            "Major": 4,
            "Minor": 2,
            "Patch": 0,
            "Build": 5
        },
        "FileFlagsMask": "3f",
        "FileFlags ": "00",
        "FileOS": "040004",
        "FileType": "01",
        "FileSubType": "00"
    },
    "StringFileInfo":
    {
        "Comments": "",
        "CompanyName": "NYAOS.ORG",
        "FileDescription": "Extended Commandline Shell",
        "FileVersion": "4.2.0_5",
        "InternalName": "",
        "LegalCopyright": "Copyright (C) 2014-2017 HAYAMA_Kaoru",
        "LegalTrademarks": "",
        "OriginalFilename": "NYAGOS.EXE",
        "PrivateBuild": "",
        "ProductName": "Nihongo Yet Another GOing Shell",
        "ProductVersion": "4.2.0_5",
        "SpecialBuild": ""
    },
    "VarFileInfo":
    {
        "Translation": {
            "LangID": "0411",
            "CharsetID": "04E4"
        }
    }
}

With this JSON, the property of the executable shows

If you want to change the fileversion of the property, you have to write FixedFileInfo (not StringFileInfo).

X-Guardian commented 6 years ago

@zetamatta, what's the point in having the FileVersion in StringFileInfo then?

hymkor commented 6 years ago

StringFileInfo has the version information as a string. FixedFileInfo does as four integers. StringFileInfo can contain the word such as -alpha,-beta or -RC1.

FixedFileInfo can not, but when two files of executables are given, we can judge which is newer by FixedFileInfo correctly because they are simple integers.

I do not know why the Windows Explorer shows only StringFileInfo.ProductVersion and FixedFileInfo.FileVersion.

But, StringFileInfo.FileVersion and FixedFileInfo.ProductVersion are not discarded. We can read the version information all from executable files by powershell script as below.

# check.ps1

$v = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($Args[0])
if( $v ){
    Write-Host("FileVersion(StringFileInfo)=",$v.FileVersion)
    Write-Host("  FileMajorPart(FixedFileInfo)=",$v.FileMajorPart)
    Write-Host("  FileMinorPart(FixedFileInfo)=",$v.FileMinorPart)
    Write-Host("  FileBuildPart(FixedFileInfo)=",$v.FileBuildPart)
    Write-Host("  FilePrivatePart(FixedFileInfo)=",$v.FilePrivatePart)
    Write-Host("ProductVersion(StringFileInfo)=",$v.ProductVersion)
    Write-Host("  ProductMajorPart(FixedFileInfo)=",$v.ProductMajorPart)
    Write-Host("  ProductMinorPart(FixedFileInfo)=",$v.ProductMinorPart)
    Write-Host("  ProductBuildPart(FixedFileInfo)=",$v.ProductBuildPart)
    Write-Host("  ProductPrivatePart(FixedFileInfo)=",$v.ProductPrivatePart)
}
[C:\] powershell -ExecutionPolicy RemoteSigned -file check.ps1 YOUREXECUTABLE.exe
FileVersion(StringFileInfo)= 4.3.3_2
  FileMajorPart(FixedFileInfo)= 4
  FileMinorPart(FixedFileInfo)= 3
  FileBuildPart(FixedFileInfo)= 3
  FilePrivatePart(FixedFileInfo)= 2
ProductVersion(StringFileInfo)= 4.3.3_2
  ProductMajorPart(FixedFileInfo)= 4
  ProductMinorPart(FixedFileInfo)= 3
  ProductBuildPart(FixedFileInfo)= 3
  ProductPrivatePart(FixedFileInfo)= 2
josephspurrier commented 6 years ago

@zetamatta Thanks for providing all this information - this is very helpful to users of this package!

X-Guardian commented 6 years ago

Cheers @zetamatta, yes I can see the same result from my exe. Even worse is that explorer displays the StringFileInfo/ProductVersion in preference to the FixedFileInfo/ProductVersion, so it is not even consistent. What a mess from Microsoft!

@josephspurrier, what do you think about adding a GoVersionInfo parameter that would populate both the FixedFileInfo and StringFileInfo product and file version properties with the same values taken from the StringFileInfo properties?

josephspurrier commented 6 years ago

@X-Guardian I think it would be good to streamline the process. How about changing the behavior so that if only the -product-version and -file-version are specified, then the other file and product versions are filled from those?

X-Guardian commented 6 years ago

@josephspurrier, that would work great for me.

josephspurrier commented 6 years ago

Would you mind submitting a pull request with the changes?

josephspurrier commented 4 years ago

Closing due to inactivity.