0
votes

I am trying to add an icon to an .NET exe built in the Visual Studio, but somehow it does not work.

Here are steps to reproduce the problem: 1. I created a new Windows Form Application application: New Project -> Windows Form Application 2. Open the resources in it: Right click on Solution -> Properties -> Resources 3. Tried to add an icon file to it: Icons -> Add Resources -> Add Exising File-> and chose an existing icon.

It appeared that the icon was added. So, I build the exe file and closed the solution, but the resulting exe file did not contain the icon in the Windows resources. I verified that by opening the exe file by Visual Studio. The Visual Studio showed resources to me, which contained the manifest and version, but no icon.

The question: what am I doing wrong? Why does the added icon not appear in the Windows resources?

2

2 Answers

0
votes

Do the resources show up in your solution explorer? If not, I would check here and follow those steps. Additionally, to check that the resource is in fact added, you can add something like this

MessageBox.Show(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames().Aggregate((x,y)=> x + " " + y ));

Note that for this to show your resource, you have to navigate to the resource in solution explorer, open properties on it, and select Build Action -> Embedded Resource. (You can also use Resource, see article here for the difference between the two options)

As a final note, after I did this, I tried using your procedure to open the .exe in Visual Studio, and I was indeed unable to find the resources in the view. However opening up the same exe in dotPeek, I was able to find the whole image I used embedded in the code, under Resources.

0
votes

Managed resources are embedded into assemblies in a different way from Win32 resources.

If the goal is just to add the default icon, it can be done using the "Application" tab in the Project Properties.

If the goal add arbitrary Win32 resources then the answer can be found here: How to embed a resource in a .NET PE executable?