如何设置EXE文件的PE头中的“文件版本”字段?

huangapple go评论72阅读模式
英文:

How to set the "file version" field in PE header of EXE files?

问题

我使用go build命令来构建一个exe文件。然后我查看文件的属性(右键点击文件->属性),在“详细信息”选项卡中,文件的版本为空。

我该如何设置exe文件的版本?

如何设置EXE文件的PE头中的“文件版本”字段?

英文:

I use go build to build a exe file.Then i view the property of the file(Right click the file -> property),In detail tab,the file's version is empty.

How i to set the version of the exe file.

如何设置EXE文件的PE头中的“文件版本”字段?

答案1

得分: 9

EXE文件版本和其他信息被嵌入为资源,这些资源是特定于Windows的,因此Go编译器不支持。你可以使用GoVersionInfo包来实现这一点(它还支持嵌入图标)。我自己没有尝试过,但它看起来很有前途,并且有很好的文档说明。

英文:

The EXE file version and other info are embedded as resources, which are specific to Windows and thus not supported by the Go compiler. You can use the package GoVersionInfo to accomplish this (it also supports embedding an icon). I haven't tried it myself, but it looks promising and well documented.

答案2

得分: 3

有一个名为go-winres的工具可以帮助你实现这个目标,你可以在go build之前或之后使用它。

运行go install github.com/tc-hib/go-winres@latest来安装它。
然后,在你的项目文件夹中运行go-winres init,这将创建一个名为winres的子文件夹。

修改winres/winres.json文件,替换图标。

运行go-winres make,这将创建一个.syso文件。
然后运行go build,查看结果。

如果你想添加一种语言,readme文件中有一个示例。我没有成功使用goversioninfo来实现,但使用go-winres可以。

英文:

There is go-winres which lets you do this, either before or after go build.

Run go install github.com/tc-hib/go-winres@latest to install it.
Then, inside your project folder, run go-winres init. This creates a subfolder named winres.

Modify winres/winres.json, and replace the icon.

Run go-winres make. This creates a .syso file.
Run go build and see the result.

If you want to add a language, there's an example in the readme file. I didn't manage to do it with goversioninfo, while it works with go-winres.

huangapple
  • 本文由 发表于 2016年2月1日 16:55:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/35126344.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定