自动在 .NET 可执行文件中嵌入多个图标

发布于 2024-09-14 05:24:49 字数 975 浏览 1 评论 0原文

我基本上与这个问题有同样的问题:在 WPF EXE 中嵌入多个图标

当您在资源管理器中单击“更改图标”时,我的 .NET 2.0 WinForms 应用程序当前具有以下内容:

EVEMon 单个图标
(来源:理查德-斯莱特。 co.uk

我想看到什么,并且按照上面文章的建议进行一些黑客攻击,我得到了这个:

EVEMon 多个图标
(来源:理查德-斯莱特。 co.uk)

但是,获取程序集所有版本信息的过程丢失了。我需要维护程序集中的版本信息,因为我的自动更新过程依赖于此来识别应用程序的已安装版本。

我还通过持续集成过程构建应用程序,因此我不希望有任何需要手动干预的步骤,那么这可以通过自动化方式实现吗?

I basically have the same issue as this question: Embed multiple icons in WPF EXE

My .NET 2.0 WinForms application currently has this when you click "Change Icon" in explorer:

EVEMon Single Icon
(source: richard-slater.co.uk)

What I would like to see, and with some hacking about as suggested by the above article I get this:

EVEMon Multiple Icons
(source: richard-slater.co.uk)

However the process of getting there all of the version information for the assembly is lost. I need to maintain the Version Information in the assembly as my auto-update process relies on this to identify the installed version of the application.

I also build the application through a continuous integration process so I would prefer not to have any steps that require manual intervention, so is this possible in an automated way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

渔村楼浪 2024-09-21 05:24:49

我刚刚创建了一个简单的工具来完成此操作,而不必弄乱 .res 文件。它是一个小型实用程序,您可以将其用作构建后事件的一部分,并允许您将特定文件夹中的所有图标文件添加到程序集中。如果我们假设您的主项目文件夹下有一个图标文件夹,您可以添加以下构建后事件:

C:\path\to\InsertIcons.exe $(TargetPath) $(ProjectDir)icons

可以在 http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/

I've just created a simple tool to do exactly this without having to mess with .res files. It is a tiny utility which you can use as part of your Post-Build event and lets you add all icon files in a particular folder to your assembly. If we assume that you have a icons folder under your main project folder you can add the following post-build event:

C:\path\to\InsertIcons.exe $(TargetPath) $(ProjectDir)icons

A further description and a download can be found at http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/

樱娆 2024-09-21 05:24:49

ChrisF提到的文章也会清除你的程序集版本信息。遵循该指南后,您可能想尝试使用此处描述的构建后方法 链接以嵌入清单。

编辑:

它是“方法#2 - “通用”方法(使用 mt.exe)”

The article mentioned by ChrisF will also wipe out your assembly version information. Once you follow that guide you might want to try using the post-build method described here Link to embed the manifest.

EDIT:

It is "Method #2 - The "Generic" Approach (using mt.exe)"

澜川若宁 2024-09-21 05:24:49

这篇代码项目文章介绍了如何执行此操作。

基本上,您可以向项目添加更多图标资源。

This Code Project article has a walkthrough on how to do this.

Basically you add more icon resources to the project.

触ぅ动初心 2024-09-21 05:24:49

对我来说,该问题的最简单解决方案是创建一个 .res 文件,其中仅包含您需要的图标(并按您的首选顺序存储它们),在项目属性中禁用主图标并合并先前准备的图标包(.res 文件)到您的最终 .exe 文件,在构建后事件中执行此操作。虽然,如果这个过程可以完全自动化并保持清单数据不变,那么最后一步需要一个外部工具(ResHacker),它允许您通过命令行执行 .res 文件合并工作(当然,Visual Studio 可以做到这一点,但据我所知,没有命令行界面可以实现它 - 如果我错了,请纠正我)。

  1. 下载空白 .res 文件 (http://www.codeproject.com/Tips/160885/How-to-Embed-Multiple-Icons-and-Color-Animated-Cur.aspx)并将其添加到您的项目< /p>

  2. < p>使用您的图标填写之前添加的 .res 文件

  3. 从项目中删除主图标(项目 -> 属性)

  4. 下载 ResHacker 工具 (http: //www.angusj.com/resourcehacker/)并将其放置在您想要的任何位置

  5. 将类似的行添加到您的构建后事件:

    if $(ConfigurationName) == Release (
      ..\..\..\..\..\Tools\ResHack\ResHacker.exe -add $(TargetPath)、$(TargetPath)、$(ProjectDir)Properties\AssemblyWin32.res ,,,
    )
    

仅此而已。每次在发布模式下编译项目时,您都会在目标 .exe 文件中获得所需的图标。

For me the simplest solution to that problem is to create a .res file, which includes only icons you need (and stores them in your preferred order), disable a main icon in project properties and merge previously prepared icon pack (.res file) to your final .exe file, doing it in post-build event. Although, if this process can be fully automated and keep your manifest data unchanged, it needs in last step a external tool (ResHacker), which allow you to do a .res file merging job via command line (of course, Visual Studio can do this, but as far I know there are no command line interface to achieve it - if I'm wrong, please correct me).

  1. Download a blank .res file (http://www.codeproject.com/Tips/160885/How-to-Embed-Multiple-Icons-and-Color-Animated-Cur.aspx) and add it to your project

  2. Fill out previously added .res file with your icons

  3. Remove main icon from your project (Project -> Properties)

  4. Download a ResHacker tool (http://www.angusj.com/resourcehacker/) and place it wherever you want

  5. Add similar line to your post-build event:

    if $(ConfigurationName) == Release (
      ..\..\..\..\..\Tools\ResHack\ResHacker.exe -add $(TargetPath), $(TargetPath), $(ProjectDir)Properties\AssemblyWin32.res ,,,
    )
    

That's all. Everytime you compile your project in Release mode you will get a wanted icons to your destination .exe file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文