GithubHelp home page GithubHelp logo

josephspurrier / goversioninfo Goto Github PK

View Code? Open in Web Editor NEW
817.0 20.0 115.0 163 KB

Golang Microsoft Windows File Properties/Version Info and Icon Resource Generator

License: MIT License

Go 98.03% Makefile 1.97%

goversioninfo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goversioninfo's Issues

Allow to specify the icon file as part of versioninfo.json

Usually, the main icon is specified as part of a Windows .rc file. With versioninfo.json being more or less the replacement for the .rc file, it would make sense to also be able to specify the icon file name in there. Also, this helps to keep the information in one place, and not spread it across versioninfo.json and command line options.

Possible issue when building with race detector?

Hi,

I've a small project I'm developing, whose windows version has an icon I was able to add thanks to your great tool.

When I try to build the project with: go build -race
I get the following error:

> go build -race
# _/[...]/Subs/ws
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
c:/go/additional/mingw64/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `C:\Users\...\AppData\Local\Temp\go-link-099298167\000000.o' is incompatible with i386:x86-64 output
collect2.exe: error: ld returned 1 exit status

Before installing the Mingw64 (and Mingw32) environment the error was that the gcc compiler was missing.

The build runs just fine if I simply remove resource.syso from the project directory.

Thank you very much

G.

P.S.

> ver
Microsoft Windows [Versione 6.1.7601]

> go version
go version go1.8 windows/amd64

make versioninfo.json optional

I'm only interested in generating a .syso file with -icon parameter, but right now I have to have an empty versioninfo.json file with {} as the contents. This seems redundant as it's not at all used.

As an alternative, I'm doing this which is quite hacky.

//go:generate /bin/bash -c "go run github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest -icon=icon.ico <(echo '{}')"

or

//go:generate /bin/bash -c "go run github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest -icon=icon.ico - <<< '{}' "

but it works.

It could be a lot better if I can just //go:generate go run $TOOL -icon=.... Thanks for creating this project!

How to use with Golang 1.22

There are changes in golang go command in 1.22 release.

go generate ./... goversioninfo -icon=favicon.ico
package goversioninfo is not in std (C:\Program Files\Go\src\goversioninfo)
malformed import path "-icon=favicon.ico": leading dash

What would be the best way to use it with new go command?

Thanks.

Is there any similar library in linux

Is there any similar library in linux
Hello. Is there a library similar to "goversioninfo" under linux to set the icons and information of executable files? I experimented with rsrc but it didn't work. thanks.

Version info is not embedded when passing main.go file to go build.

Assume I have a project structure like this:

  • myapp
    • app
      • icon.ico
      • main.go
      • versioninfo.json
    • dist

When I run

./myapp/app>go generate
./myapp/app>go build main.go

The version info is not embedded inside the exe. Leaving off main.go from the go build command works. In this case it doesn't make a difference, but it does make a difference when you want to run go generate and build from another folder:

./myapp>go generate .\app
./myapp>go build -o .\dist\app.exe .\app\main.go

Do I have the command wrong? Should this be possible?

"goversioninfo": executable file not found in $PATH

When I try to run go generate I get the following message:
running "goversioninfo": exec: "goversioninfo": executable file not found in $PATH however go is in my PATH.

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/go/bin

for reference, I am on OSX.

Is it compatible with 64bits?

go build gives this error.
What is wrong?
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status

Generated resource.syso file should be platform specific

If I use the same directory on Windows and Linux (or if I try to do a Windows build followed by a Linux build), then I get errors that look like this:

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: i386 architecture of input file `/tmp/go-link-787743683/000000.o' is incompatible with i386:x86-64 output
collect2: error: ld returned 1 exit status

The problem is that golang is trying to link the resource.syso file to the linux executable, which of course doesn't work. The solution is to have the generated file be platform specific -- so instead of resource.syso, the generate step should generate resource_windows_386.syso or resource_windows_amd64.syso depending on the values of the GOARCH variable.

I can use the -o flag to work around this, but it would be a good default to have too.

Cannot specify new icon

I have successfully set the icon for my exe, but after I replaced it with a new icon.ico file and used go generate and go build to rebuild the exe, the exe icon was still the original one. How to solve this problem? My environment is win10.

Icon file not correctly closed

In follow up to PR #28 and issue #29 here is the simplest test to illustrate the problem.

I am still working through an alternative solution but I can't figure out how the os.Open(fname) in icon.go is being closed without the defer f.Close()

package goversioninfo

import (
	"log"
	"os"
	"runtime"
	"testing"
)

func TestTempIcon(t *testing.T) {
	icoPath := "tmp.ico"
	outPath := "resource.syso"
	vi := &VersionInfo{}
	vi.IconPath = icoPath

	f, _ := os.Create(icoPath)
	err := f.Close()
	if err != nil {
		log.Println("Unexpected error closing new file")
	}

	vi.Build()
	vi.Walk()
	err = vi.WriteSyso(outPath, runtime.GOARCH)
	if err != nil {
		log.Println("Unexpected error writing resource")
	}

	err = os.Remove(icoPath)
	if err != nil {
		t.Fatal("Error deleting temporary icon", err)
	}
}

undefined: pe.IMAGE_FILE_MACHINE_ARMNT

Hi, faced with issue during install this tool for gitlabci.
Docker image golang:1.11

> go env
 GOARCH="amd64"
 GOBIN=""
 GOEXE=""
 GOFLAGS=""
 GOHOSTARCH="amd64"
 GOHOSTOS="linux"
 GOOS="linux"
 GOPROXY=""
 GORACE=""
 GOROOT="/usr/local/go"
 GOTMPDIR=""
 GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
 GCCGO="gccgo"
 CC="gcc"
 CXX="g++"
 CGO_ENABLED="1"
 GOMOD=""
 CGO_CFLAGS="-g -O2"
 CGO_CPPFLAGS=""
 CGO_CXXFLAGS="-g -O2"
 CGO_FFLAGS="-g -O2"
 CGO_LDFLAGS="-g -O2"
 PKG_CONFIG="pkg-config"
 GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build171150044=/tmp/go-build -gno-record-gcc-switches"

Error output

> go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
 # github.com/akavel/rsrc/coff
 .cache/src/github.com/akavel/rsrc/coff/coff.go:169:18: undefined: pe.IMAGE_FILE_MACHINE_ARMNT
 .cache/src/github.com/akavel/rsrc/coff/coff.go:265:7: undefined: pe.IMAGE_FILE_MACHINE_ARMNT

Is it possible to speed up the runtime of goversioninfo?

Please forgive me if this is not the right place for the question.

I build Syncthing executables for Windows on a regular basis, and running goversioninfo takes as much as 50s out of the 60s-long process (see https://forum.syncthing.net/t/16302/8 for details). I am wondering whether there is anything that could be done to speed up the whole process. If I skip the execution of goversioninfo, the compilation times drops to just a few seconds, so there is a huge difference between using and not using it 😔.

Setting the IDI_APPLICATION icon?

I have a Go application on Windows 10+ that is using WebView for the GUI. It works great but I am having trouble setting the Window icon. This is not the icon on the EXE. That part works great. But I need to set the icon on the top left corner of the windows that WebView creates. In the resource file, it is referred to as the IDI_APPLICATION icon (32512). 100 is the EXE icon I believe.

See: https://github.com/webview/webview

e.g. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadiconw

100  ICON "icons\\main.ico"
32512 ICON "icons\\small.ico"

Does goversioninfo have an undocumented entry to set this?

Unfortunately, I'm not a Win32 expert.
Thanks

rsrc merge failure: corrupt .rsrc section

C:/Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: $WORK\b001\exe\a.out.exe: .rsrc merge failure: corrupt .rsrc section

The go generate command is
//go:generate goversioninfo -64 -icon=./resource/pipeline.ico -manifest=./resource/PipeIt.exe.manifest

My platform is Windows 10 64bit with go version go1.13.5 windows/amd64

"goversioninfo": executable file not found in $PATH

When attempting to run go generate using your software on OSX the following error appears on the terminal:

main_test.go:1: running "goversioninfo": exec: "goversioninfo": executable file not found in $PATH

I did not find a step relating to adding goversioninfo to the $PATH. Is there something that I am missing?

I am cross compiling for Windows 7 32 bits but I am developing on a Mac OSX.

Build Issue

Hi,

I just tried to use go build and I got the following error:

C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `C:\Users\WOG\AppData\Local\Temp\go-link-000595971\000000.o' is incompatible with i386:x86-64 output
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: $WORK\b001\exe\a.out.exe: .rsrc merge failure: corrupt .rsrc section
collect2.exe: error: ld returned 1 exit status

Details not added

hello all I'm doing the following:

goversioninfo -platform-specific=true
go build -o simulator.exe

but in the .exe file details i dont have any information. The versioninfo.json is in the main.go path

file-version argument do nothing if other fields has null values?

i've tried to insert to my code this directive and nothing happened after go build.

//go:generate goversioninfo -file-version="1.2.3.4"

I guess my argument overriden by default values from versioninfo.json

"FixedFileInfo": { "FileVersion": { "Major": 1, "Minor": 0, "Patch": 0, "Build": 0 },

is that a bug or feature?

Add Support for ARM builds

For $Env:GOARCH="arm" I get the below error,

# gitlab.com/instasafesdp/instasafe.ztna.services.go
C:\Users\RUNNER~1\AppData\Local\Temp\go-build1204466033\b001\_pkg_.a(resource.syso): 160839: unknown ARM relocation type 7

This is because the resource.syso does not have ARM support.

Product version disappears when it ends with zero

strings that appear: "0.0.10 ", "0.0.11"
strings that don't appear: "1.0", "0.10"

versioninfo.json contents:
{
"StringFileInfo":
{
"ProductVersion": "1.0"
}
}

test.go contents:
//go:generate goversioninfo

package main

func main(){
print("hello")
}

set -file-version from shell

Hi there,

not really an issue, could you show how to set -file-version from shell, without having to fill it in versioninfo.json ?
I am trying to run something like

go generate goversioninfo -file-version="3.3.3" -icon=testdata/resource/icon.ico cmd/util/main.go

but with no success, still the versioninfo.json file has priority over the parameter.
I also tried passing -skip-versioninfo but in that case I get ver. 0.0.0.0

JSON observations

1. Product Version under FixedFileInfo has no effect when StringFileInfo is not present

Steps to reproduce:

  • Remove everything except FixedFileInfo.

Observation

  • File Version will reflect while Product Version won't
{
  "FixedFileInfo": {
    "FileVersion": {
      "Major": 2,
      "Minor": 0,
      "Patch": 0,
      "Build": 0
    },
    "ProductVersion": {
      "Major": 2,
      "Minor": 0,
      "Patch": 0,
      "Build": 0
    }
  }
}

image

2. File Version is missing when FixedFileInfo is not present

Steps

  • Remove everything except StringFileInfo
  • Provide file and product versions

Observation

  • File version is wrong while production version will reflect.
    image
    image

3. FileFixedInfo supersedes StringFileInfo

Steps

  • Provide different values for both file and product versions in both Info objects.

Observation

  • Values in FileFixedInfo is reflected while those in StringFileInfo is ignored.

Bug/Issue/Comments

There should be some sort of validation or better, let file and production versions by supplied from FileFixedInfo only and the rest from the other part.

Currently I need to supply BOTH of FileFixedInfo and StringFileInfo due to issues 1 and 2.

4. No validation

FileFixedInfo is organized into major, minor, etc which is good. But StringFileInfo accepts any arbitrary value and no errors are thrown during go generate

32 bit build request

Hi,

I just got it to build with 32 bit go pretty easily and would like to ask if you'd consider putting out an installer for 32 bit =] I'm using a surface pro x, which is an arm64 processor but has 32 bit emulation support. Since golang isn't out for windows / arm64 having a build for 32 bit is the next best thing but at least lets us use the tool on this and other windows arm devices =]

Thanks for thinking about it!

side by side configuration is incorrect

I get this when I open the exe. In the application log, it gives

Activation context generation failed for "C:\Users\rawas\Downloads\light-mde (1).exe". Dependent Assembly Github.com.JosephSpurrier.GoVersionInfo,language="&#x2a;",processorArchitecture="&#x2a;",type="win32",version="1.0.0.0" could not be found. Please use sxstrace.exe for detailed diagnosis.

error on "go get"

Hello,
I have a strange behaviour on the "go get", I have an error message :

src\github.com\josephspurrier\goversioninfo\goversioninfo.go:194:13: coff.Arch undefined (type *coff.Coff has no field or method Arch)

I'm under Windows 10 and I use the last version of akavel/rsrc

Windows arm64 support

I tried to use this with windows/arm64 builds but it gives this error on the linking phase of go build

.cache/go-build/f1/f13c0b04e69e2d7e70204317beade39f0ac862d38feaad4c004fa51a0ea84395-d(resource_windows): 901175: unknown ARM64 relocation type 7

Or if I add the -64 flag it gives

.cache/go-build/c8/c85a2f24ad6ddbc2a4f6ca33758601e7ad33f88a1ca9fefe6b9b5f7e188e153d-d(resource_windows): 901175: unknown ARM64 relocation type 3

The resource file generated looks like this with file so I guess it needs a specific flag to generate arm64?

resource_windows_arm64.syso: Intel amd64 COFF object file, no line number info, not stripped, 1 section, symbol offset=0x666d, 1 symbols, 1st section name ".rsrc"

In the mean time, no icons for Windows/arm64 users :-)

File version property always 0.0.0.0 when using StringFileInfo FileVersion

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

Is it right that the field (Patch,Build) assigned to (BuildPart,PrivatePart) ?

The field "Patch" looks assigned to the property .BuildPart which is seen by PowerShell ,
and "Build" to .PrivatePart. Is it right ?

The case of the versioninfo.json like this:

		"FileVersion": {
			"Major": 6,
			"Minor": 3,
			"Patch": 9600,
			"Build": 17284
		},

See version information with PowerShell like below

$v = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($Args[0]) 
if( $v ){
    Write-Host("FileVersion=",$v.FileVersion)
    Write-Host("  FileMajorPart=",$v.FileMajorPart)
    Write-Host("  FileMinorPart=",$v.FileMinorPart)
    Write-Host("  FileBuildPart=",$v.FileBuildPart)
    Write-Host("  FilePrivatePart=",$v.FilePrivatePart)
    Write-Host("ProductVersion=",$v.ProductVersion)
    Write-Host("  ProductMajorPart=",$v.ProductMajorPart)
    Write-Host("  ProductMinorPart=",$v.ProductMinorPart)
    Write-Host("  ProductBuildPart=",$v.ProductBuildPart)
    Write-Host("  ProductPrivatePart=",$v.ProductPrivatePart)
}

The result:

>powershell -ExecutionPolicy RemoteSigned -file C:\Users\Hayama\go\src\github.co
m\zetamatta\experimental\goversioninfo_issue\showver.ps1 goversioninfo_issue.exe

FileVersion= 6.3.9600.17284 (aaa.140822-1915)
  FileMajorPart= 6
  FileMinorPart= 3
  FileBuildPart= 9600
  FilePrivatePart= 17284
ProductVersion= 6.3.9600.17284
  ProductMajorPart= 6
  ProductMinorPart= 3
  ProductBuildPart= 9600
  ProductPrivatePart= 17284

demo-20160626.zip

Read version info

I have been looking all morning for a way to read file info (version in particular) from a DLL or EXE, and I keep finding links to this package even though it does the opposite. Is there any interest in implementing a sort of resource file generator to pull this info into a file from where it is embedded? Either way, do you have any tips for where I should research this?

After #28, `already closed` error

@andydotxyz and @josephspurrier :

After We should close files, be a good citizen by andydotxyz · Pull Request #28 · josephspurrier/goversioninfo was merged, an error occurs like below :

2019/01/23 14:59:10 Error writing syso: error writing "nyagos.syso": read nyagos.ico: file already closed

for

goversioninfo.exe -file-version=4.4.0_1-7-g0275d5b -product-version=4.4.0_1-7-g0275d5b -icon=nyagos.ico -ver-major=0 -ver-minor=0 -ver-patch=0 -ver-build=0 -product-ver-major=0 -product-ver-minor=0 -product-ver-patch=0 -product-ver-build=0 -o nyagos.syso versioninfo.json

Program terminates without errors when using the resource.syso

My program quits at the following code when using the resource.syso generated from this package. Without it, it works fine. There are no errors. I've no clue what's going on here, since the program can create a directory and a log file just fine.

	// Open the storage db (access token, etc.)
	db, err = sql.Open("sqlite3", makePath("storage.db"))
	if err != nil {
		log.Printf("Error opening storage.db: %s", err)
	}
	
	log.Print("THIS IS LOGGED")

	if _, err = db.Exec(`CREATE TABLE IF NOT EXISTS data(
		key		STRING	PRIMARY KEY NOT NULL,
		value	STRING	NOT NULL
	)`); err != nil {
		log.Printf("Error creating storage.db table: %s", err)
	}
	
	log.Print("THIS ISN'T LOGGED (program has terminated)")

This is my versioninfo.json: https://hasteb.in/oficovut.json
And this is my manifest (though same issue without it): https://hasteb.in/wuyeyira.xml

edit: After a lot of digging I found the issue, see my reply here: #39

dependencies not found (anymore)

i already used your module in an tool.
today i tried to rebuild it, and now it fails to build.
tried to install goversioninfo

> go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo
no required module provides package github.com/josephspurrier/goversioninfo/cmd/goversioninfo; to add it:
        go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
> go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
github.com/josephspurrier/goversioninfo/cmd/goversioninfo imports
        github.com/josephspurrier/goversioninfo imports
        github.com/akavel/rsrc/binutil: cannot find module providing package github.com/akavel/rsrc/binutil
github.com/josephspurrier/goversioninfo/cmd/goversioninfo imports
        github.com/josephspurrier/goversioninfo imports
        github.com/akavel/rsrc/coff: cannot find module providing package github.com/akavel/rsrc/coff
github.com/josephspurrier/goversioninfo/cmd/goversioninfo imports
        github.com/josephspurrier/goversioninfo imports
        github.com/akavel/rsrc/ico: cannot find module providing package github.com/akavel/rsrc/ico

the same happens if i try to build my tool.

UPDATE:
it seems the download of the dependent module was corrupted or unpacked incorrect.
i unpacked it manually and now the install worked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.