Categorygithub.com/josephspurrier/goversioninfo
modulepackage
1.4.1
Repository: https://github.com/josephspurrier/goversioninfo.git
Documentation: pkg.go.dev

# README

GoVersionInfo

Go Report Card Build Status Coverage Status GoDoc

Microsoft Windows File Properties/Version Info and Icon Resource Generator for the Go Language

Package creates a syso file which contains Microsoft Windows Version Information and an optional icon. When you run "go build", Go will embed the version information and an optional icon and an optional manifest in the executable. Go will automatically use the syso file if it's in the same directory as the main() function.

Example of the file properties you can set using this package:

Image of File Properties

Usage

To install, run the following command:

go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo

Copy testdata/resource/versioninfo.json into your working directory and then modify the file with your own settings.

Add a similar text to the top of your Go source code (-icon and -manifest are optional, but can also be specified in the versioninfo.json file):

//go:generate goversioninfo -icon=testdata/resource/icon.ico -manifest=testdata/resource/goversioninfo.exe.manifest

Run the Go commands in this order so goversioninfo will create a file called resource.syso in the same directory as the Go source code.

go generate
go build

Command-Line Flags

Complete list of the flags for goversioninfo:

  -charset=0: charset ID
  -comment="": StringFileInfo.Comments
  -company="": StringFileInfo.CompanyName
  -copyright="": StringFileInfo.LegalCopyright
  -description="": StringFileInfo.FileDescription
  -example=false: dump out an example versioninfo.json to stdout
  -file-version="": StringFileInfo.FileVersion
  -icon="": icon file name
  -internal-name="": StringFileInfo.InternalName
  -manifest="": manifest file name
  -skip-versioninfo=false: skip version info reading on true, allows setting just icon
  -o="resource.syso": output file name
  -gofile="": Go output file name (optional) - generates a Go file to access version information internally
  -gofilepackage="main": Go output package name (optional, requires parameter: 'gofile')
  -platform-specific=false: output i386 and amd64 named resource.syso, ignores -o
  -original-name="": StringFileInfo.OriginalFilename
  -private-build="": StringFileInfo.PrivateBuild
  -product-name="": StringFileInfo.ProductName
  -product-version="": StringFileInfo.ProductVersion
  -special-build="": StringFileInfo.SpecialBuild
  -trademark="": StringFileInfo.LegalTrademarks
  -translation=0: translation ID
  -64:false: generate 64-bit binaries on true
  -arm:false: generate ARM binaries on true
  -ver-major=-1: FileVersion.Major
  -ver-minor=-1: FileVersion.Minor
  -ver-patch=-1: FileVersion.Patch
  -ver-build=-1: FileVersion.Build
  -product-ver-major=-1: ProductVersion.Major
  -product-ver-minor=-1: ProductVersion.Minor
  -product-ver-patch=-1: ProductVersion.Patch
  -product-ver-build=-1: ProductVersion.Build

You can look over the Microsoft Resource Information: VERSIONINFO resource

You can look through the Microsoft Version Information structures: Version Information Structures

PowerShell Differences

In PowerShell, the version components are named differently than the fields in the versioninfo.json file:

PowerShell:          versioninfo.json:
-----------          -----------------
FileMajorPart      = FileVersion.Major
FileMinorPart      = FileVersion.Minor
FileBuildPart      = FileVersion.Patch
FilePrivatePart    = FileVersion.Build
ProductMajorPart   = ProductVersion.Major
ProductMinorPart   = ProductVersion.Minor
ProductBuildPart   = ProductVersion.Patch
ProductPrivatePart = ProductVersion.Build

If you find any other differences, let me know.

Alternatives to this Tool

You can also use windres to create the syso file. The windres executable is available in either MinGW or tdm-gcc.

Below is a sample batch file you can use to create a .syso file from a .rc file. There are sample .rc files in the testdata/rc folder.

@ECHO OFF

SET PATH=C:\TDM-GCC-64\bin;%PATH%
REM SET PATH=C:\mingw64\bin;%PATH%

windres -i testdata/rc/versioninfo.rc -O coff -o versioninfo.syso

PAUSE

The information on how to create a .rc file is available here. You can use the testdata/rc/versioninfo.rc file to create a .syso file that contains version info, icon, and manifest.

Issues

The majority of the code for the creation of the syso file is from this package: https://github.com/akavel/rsrc

There is an issue with adding the icon resource that prevents your application from being compressed or modified with a resource editor. Please use with caution.

Major Contributions

Thanks to Tamás Gulácsi for his superb code additions, refactoring, and optimization to make this a solid package.

Thanks to Mateusz Czaplinski for his embedded binary resource package with icon and manifest functionality.

# Packages

# Constants

Cs7ASCII: 0 0000 7-bit ASCII.
CsArabic: 1256 04E8 Arabic.
CsBig5: 950 03B6 Taiwan (Big5).
CsCyrillic: 1251 04E3 Cyrillic.
CsGreek: 1253 04E5 Greek.
CsHebrew: 1255 04E7 Hebrew.
CsJIS: 932 03A4 Japan (Shift ? JIS X-0208).
CsKSC: 949 03B5 Korea (Shift ? KSC 5601).
CsLatin2: 1250 04E2 Latin-2 (Eastern European).
CsMultilingual: 1252 04E4 Multilingual.
CsTurkish: 1254 04E6 Turkish.
CsUnicode: 1200 04B0 Unicode.
LngAlbanian: 0x041C Albanian.
LngArabic: 0x0401 Arabic.
LngBahasa: 0x0421 Bahasa.
LngBelgian Dutch: 0x0813 Belgian Dutch.
LngBelgian French: 0x080C Belgian French.
LngBulgarian: 0x0402 Bulgarian.
LngCanadian French: 0x0C0C Canadian French.
LngCastilianSpanish: 0x040A Castilian Spanish.
LngCatalan: 0x0403 Catalan.
LngCroatoSerbianLatin: 0x041A Croato-Serbian (Latin).
LngCzech: 0x0405 Czech.
LngDanish: 0x0406 Danish.
LngDutch: 0x0413 Dutch.
LngFinnish: 0x040B Finnish.
LngFrench: 0x040C French.
LngGerman: 0x0407 German.
LngGreek: 0x0408 Greek.
LngHebrew: 0x040D Hebrew.
LngHungarian: 0x040E Hungarian.
LngIcelandic: 0x040F Icelandic.
LngItalian: 0x0410 Italian.
LngJapanese: 0x0411 Japanese.
LngKorean: 0x0412 Korean.
LngNorwegianBokmal: 0x0414 Norwegian ? Bokmal.
LngNorwegianNynorsk: 0x0814 Norwegian ? Nynorsk.
LngPolish: 0x0415 Polish.
LngPortugueseBrazil: 0x0416 Portuguese (Brazil).
LngPortuguese (Portugal): 0x0816 Portuguese (Portugal).
LngRhaetoRomanic: 0x0417 Rhaeto-Romanic.
LngRomanian: 0x0418 Romanian.
LngRussian: 0x0419 Russian.
LngSerboCroatianCyrillic: 0x081A Serbo-Croatian (Cyrillic).
LngSimplifiedChinese: 0x0804 Simplified Chinese.
LngSlovak: 0x041B Slovak.
LngSpanishMexico: 0x080A Spanish (Mexico).
LngSwedish: 0x041D Swedish.
LngSwiss French: 0x100C Swiss French.
LngSwiss German: 0x0807 Swiss German.
LngSwiss Italian: 0x0810 Swiss Italian.
LngThai: 0x041E Thai.
LngTraditionalChinese: 0x0404 Traditional Chinese.
LngTurkish: 0x041F Turkish.
LngUKEnglish: 0x0809 U.K.
LngUrdu: 0x0420 Urdu.
LngUSEnglish: 0x0409 U.S.

# Structs

FileVersion with 3 parts.
FixedFileInfo contains file characteristics - leave most of them at the defaults.
SizedReader is a *bytes.Buffer.
StringFileInfo is what you want to change.
Translation with langid and charsetid.
VarFileInfo is the translation container.
VersionInfo data container.
VSFixedFileInfo - most of these should be left at the defaults.
VSString holds the keys and values.
VSStringFileInfo holds multiple collections of keys and values, only allows for 1 collection in this package.
VSStringTable holds a collection of string keys and values.
VSVar holds the translation key.
VSVarFileInfo holds the translation collection of 1.
VSVersionInfo is the top level version container.

# Type aliases

CharsetID must use be a character-set identifier from: https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx#charsetID.
LangID must use be a character-set identifier from: https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx#langID.