mxre / winres

Create and set windows icons and metadata for executables with a rust build script
MIT License
297 stars 42 forks source link

Question about ProductVersion and FileVersion #9

Closed Boscop closed 6 years ago

Boscop commented 6 years ago

FileVersion is not listed in the supported variables of this crate, but my exe still has a FileVersion (0.1.0.0). Is it set by cargo based on the version set it Cargo.toml? Or also set by this crate?

Shouldn't the ProductVersion always be the same as FileVersion when publishing the exe?

How can I keep the ProductVersion (and FileVersion) automatically the same as the version set in Cargo.toml? :)

mxre commented 6 years ago

The VersionInfo struct that is generated and stored as a resource inside the EXE/DLL contains version information stored as numeric data and a string table.

So if you talk about FileVersion / ProductVersion there are two fields that can be different either as the numeric information or in the string table. If you only set the version in the package section of Cargo.toml than this crate will use this verion when calling WindowsResource::new() (this relies on cargo setting the environment variables $CARGO_PKG_VERSION when calling build.rs inside your crate)

FileVersion is not listed in the supported variables of this crate

I'm not entirely sure what you mean by saying FileVersion is not in the list of supported variables. The documentation mentions it several times. If you refer to the secion of the README then this is in reference to the Windows 10 File Explorer's Properties Fields. These are the StringTable keys that are shown in this Dialog. FileVersion in the Windows Explorer is from the numeric version information. (I know this can be confusing)

Shouldn't the ProductVersion always be the same as FileVersion when publishing the exe?

Not necessary, e.g. cl.exe Microsoft's C/C++ Compiler has a FileVersion of 19. where as ProductVersion of 14. this is in reference to beeing part of Visual Studio 14. The crate allows you to define version numbers as you like.

How can I keep the ProductVersion (and FileVersion) automatically the same as the version set in Cargo.toml?

You shouldn't need to do anything. As previously stated the crate should take care of these things.

I hope this isn't too confusing, It would help a bit if you would have provided some example code, so I could give a more concrete answer.

Boscop commented 6 years ago

Thanks. Btw, should the version be in binary or decimal format? MS docs say binary but it seems to work when I set it in decimal.

mxre commented 6 years ago

If you refer to the version field in Cargo.toml package section, look at the Cargo.toml Documentation

If you want to set the Version Information manually you need to generate a u64 out of the 4 u16 components in the version:

So a.b.c.d is

let wres = WindowsResource::new();
let mut version = 0 as u64;
version |= a << 48;
version |= b << 32;
version |= c << 16;
version |= d
wres.set_version_info(VersionInfo::FILEVERSION, version);
wres.set_version_info(VersionInfo::PRODUCTVERSION, version);

The String Fields (set by package.metadata.winres in Cargo.toml or using WindowsResource.set()) can be any unicode string, but are usually the same as the numeric ones.