1.首先要安装mingw,安装完后,在c:\mingw64\bin\下,有一个windres.exe文件,且增加到了环境变量path中
2. 在项目中建个子文件夹,比如ver,然后把图标文件复制到里面,比如xx.ico
3. 创建xx.manifest文件,内容如下
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
</assembly>
4. 创建xx.rc文件,编码为utf-8,注意里面的ico与manifest的文件名,内容如下:
#pragma code_page(65001)
#include "version.h"
#define RT_MANIFEST 24
#define VER_MAJOR 1
#define VER_MINOR 0
#define VER_PATCH 0
#define MAKEVER_S(a,b,c,d) a,b,c,d
#define MAKEVER(a,b,c,d) a.b.c.d
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
1 VERSIONINFO
FILEVERSION MAKEVER_S(VER_MAJOR, VER_MINOR, VER_PATCH, VER_REVISION)
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "公司名称"
VALUE "FileDescription", "文件描述"
VALUE "InternalName", "xx"
VALUE "LegalCopyright", "Copyright (C) 2023. Xx. All Rights Reserved."
VALUE "OriginalFilename", "xx.exe"
VALUE "ProductName", "产品名称"
VALUE "ProductVersion", TOSTRING(MAKEVER(VER_MAJOR, VER_MINOR, VER_PATCH, VER_REVISION))
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END
1 ICON "xx.ico"
1 RT_MANIFEST "xx.manifest"
5.创建文件make.bat,内容如下,make.bat是用于自动生成version.bat与version.h文件的
if exist "version.bat" (call version.bat) else (set /a REVSION=0)
if "%REVSION%" == "" (set /a REVSION=0)
set /a REVSION+=1
if exist "version.bat" (del /q "version.bat")
(echo set REVSION=%REVSION%)>version.bat
(echo #define VER_REVISION %REVSION%)>version.h
6.在项目文件夹下,建build.bat文件,注意并不是ver下,内容如下
rem echo off
cd ver
call make.bat
windres -i xx.rc -o rsrc.syso
copy rsrc.syso ..
cd..
go build -ldflags "-s -w"
这样,每次需要编译的时候,运行build.bat的时候,就会生成xx.exe文件,此时这个文件的图标为复制到ver下的ico文件,开始会显示1.0.0.1,以后每次编译,最后1位都会自增1,如果想要隐然控制台窗口,只需要再加1个参数-H windowsgui即可,文件的详细信息也可以通过xx.rc文件进行修改