Has anyone here embedded metadata into a Go binary onto Windows?

blov · · 455 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a small agent which I&#39;m compiling for Linux, OSX and Windows and I&#39;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&#39;t worked much with Windows in a long time. I&#39;m hoping there&#39;s some relatively painless way to do this with a Go binary.</p> <hr/>**评论:**<br/><br/>JHunz: <pre><p>It&#39;s pretty simple.<br/> 1) Create a .rc resource file with the properties desired. There are many resources online for resource file info. Here&#39;s a stripped-down version of the one we publish: </p> <pre><code>#include &lt;winver.h&gt; #include &lt;winuser.h&gt; // 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 &#34;StringFileInfo&#34; BEGIN BLOCK &#34;040904b0&#34; BEGIN VALUE &#34;CompanyName&#34;, &lt;company&gt; VALUE &#34;FileDescription&#34;, &lt;description&gt; VALUE &#34;FileVersion&#34;, &lt;file version&gt; VALUE &#34;LegalCopyright&#34;, &lt;copyright string&gt; VALUE &#34;ProductName&#34;, &lt;product name&gt; VALUE &#34;ProductVersion&#34;, &lt;product version&gt; END END BLOCK &#34;VarFileInfo&#34; BEGIN VALUE &#34;Translation&#34;, 0x409, 1200 END END </code></pre> <p>2) Include a windres step in your build process to compile it in. </p> <pre><code>if &#34;%ARCH%&#34; == &#34;amd64&#34; ( set WINDRESFLAGS=-F pe-x86-64 ) else ( set WINDRESFLAGS=-F pe-i386 ) windres -l 0 %WINDRESFLAGS% -o &lt;output .syso filename, put it in the directory your main file is in&gt; &lt;rc file&gt; // 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&#39;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&#39;s slick. Thanks!</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

455 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传