如何添加PE元数据?
Windows PE(可移植可执行文件)文件包含显示在文件“属性”对话框中“详细信息”选项卡下的元数据。似乎任意元数据都可以出现在那里。
我想要做的是将一段元数据添加到我构建的 C# 类库中,其值是来自构建项目的 git 存储库 HEAD 的提交 id。我不能只使用 CLR AssemblyVersionAttribute
来设置 git 提交 ID,因为 CLR 要求它以标准 abcd
版本格式显示。此外,我希望保留对用户有意义的版本号,但在给定实际的 PE 文件的情况下,总是有办法查找可以重新创建它的提交 ID。
如果有一个托管 API 可以完成这项工作,那就更好了,但我愿意通过 P/Invoke 来完成这项工作。
Windows PE (portable executable) files contain metadata that appear in the file's Properties dialog under the Details tab. It appears that arbitrary metadata can appear there.
What I'd like to do is add a piece of metadata to a C# class library that I build whose value is the commit id from the git repo HEAD the project was built from. I can't just use the CLR AssemblyVersionAttribute
to set the git commit id because the CLR requires that that show up in the standard a.b.c.d
version format. Besides, I'd ideally like to keep the user-meaningful version number there, but always have a way to look up, given the actual PE file, the commit id that could recreate it.
If there's a managed API to do it, so much the better, but I'm willing to P/Invoke to get this done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“详细信息”选项卡中的信息来自 VERSIONINFO 资源,但我不确定如何从 .NET 世界访问该资源...
The information in the Details tab comes from a VERSIONINFO resource but I'm not sure how you would access that from the .NET world...
啊!我刚刚发现了
AssemblyInformationalVersionAttribute
,它允许给出任意字符串,该字符串在所述对话框的“详细信息”选项卡中显示为“产品版本”值。这看起来可能正是我需要的东西。Ah! I just discovered the
AssemblyInformationalVersionAttribute
, which allows for an arbitrary string to be given that appears as the "Product version" value in the Details tab of said dialog. This looks like it might be just the thing I need.