-
-
Notifications
You must be signed in to change notification settings - Fork 51
1.3
twgh edited this page Jun 14, 2022
·
1 revision
本文章基于go1.17版本创作,1.16和1.17经过测试没有问题,1.18版本暂未测试。
本文所需要的工具来自于:https://github.com/josephspurrier/goversioninfo
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest
执行完毕后GOPATH的bin目录里出现一个goversioninfo.exe则为成功。
关键的一行代码就是//go:generate goversioninfo
//go:generate goversioninfo
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("hello world")
for {
time.Sleep(time.Hour)
}
}
json文件内容是:
{
"FixedFileInfo": {
"FileVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"ProductVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"FileFlagsMask": "3f",
"FileFlags ": "00",
"FileOS": "040004",
"FileType": "01",
"FileSubType": "00"
},
"StringFileInfo": {
"Comments": "这是程序描述",
"CompanyName": "这是公司名称",
"FileDescription": "这是文件说明",
"FileVersion": "v1.0.0.0",
"InternalName": "这是程序内部名称",
"LegalCopyright": "Copyright (c) 2021 XCGUI",
"LegalTrademarks": "",
"OriginalFilename": "这是原始文件名",
"PrivateBuild": "",
"ProductName": "这是产品名称",
"ProductVersion": "v1.0.0.0",
"SpecialBuild": ""
},
"VarFileInfo": {
"Translation": {
"LangID": "0804",
"CharsetID": "04B0"
}
},
"IconPath": "icon.ico",
"ManifestPath": ""
}
找一个ico图标命名为icon.ico放到项目目录。 然后执行命令:
go generate
成功则会在目录中生成一个resource.syso文件,只用生成一次就行了,改变了json或图标的话,需要再次生成。
最后执行go build