<p>I have a small agent which I'm compiling for Linux, OSX and Windows and I'd like to embed version, maintainer, etc info in the executable itself. The kind of information you can see in the properties dialog for the executable.</p>
<p>I haven't worked much with Windows in a long time. I'm hoping there's some relatively painless way to do this with a Go binary.</p>
<hr/>**评论:**<br/><br/>JHunz: <pre><p>It's pretty simple.<br/>
1) Create a .rc resource file with the properties desired. There are many resources online for resource file info. Here's a stripped-down version of the one we publish: </p>
<pre><code>#include <winver.h>
#include <winuser.h>
// VERSION INFO
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,0,0,0
PRODUCTVERSION 3,0,0,0
FILEFLAGSMASK 0x3fL
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", <company>
VALUE "FileDescription", <description>
VALUE "FileVersion", <file version>
VALUE "LegalCopyright", <copyright string>
VALUE "ProductName", <product name>
VALUE "ProductVersion", <product version>
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
</code></pre>
<p>2) Include a windres step in your build process to compile it in. </p>
<pre><code>if "%ARCH%" == "amd64" (
set WINDRESFLAGS=-F pe-x86-64
) else (
set WINDRESFLAGS=-F pe-i386
)
windres -l 0 %WINDRESFLAGS% -o <output .syso filename, put it in the directory your main file is in> <rc file>
// Regular main build goes here
</code></pre></pre>tech_tuna: <pre><p>Awesome, thanks!</p></pre>kardianos: <pre><p>Look at how this package does it in their examples:
<a href="https://github.com/lxn/walk" rel="nofollow">https://github.com/lxn/walk</a></p></pre>tech_tuna: <pre><p>Very cool, thank you!</p></pre>shovelpost: <pre><p>I've done it by using the JSON format found in <a href="https://github.com/josephspurrier/goversioninfo" rel="nofollow">https://github.com/josephspurrier/goversioninfo</a>. You can even embed an icon which is pretty cool.</p></pre>tech_tuna: <pre><p>Oh wow, that's slick. Thanks!</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传