0

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?

svat
  • 136
  • 6

3 Answers3

0

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.

Community
  • 1
  • 1
Kolichikov
  • 2,944
  • 31
  • 46
  • I see the added icon in the Resource folder. When I added MessageBox, I saw: `.Properties.Resources.resources>`. Then I changed 'Build Action' to 'Embedded Resources', the message changed to: `.Resources. Properties.Resources.resources>` but I still was not able to see the icon among Windows resources when I open the exe file. – svat Oct 02 '15 at 19:57
  • Is the objective to see the icon when opening the exe file through Visual Studio? Or is it to add the icon to the dll? Because you have achieved the latter, and the former might be a limitation of Visual Studio. I was able to see the resource embedded by using dotPeek, which seems a little more robust at handling exes – Kolichikov Oct 02 '15 at 20:05
  • The objective is to add the chosen icon to the exe resources. No matter what tool I use, I see no icon in the exe resources. Maybe it got embedded somewhere, but it is not in the resources. – svat Oct 02 '15 at 20:22
  • So is the problem that the icon doesn't show up where you expect it when you're launching your exe (I'm assuming in the form titlebar?) Otherwise, can you install dotPeek, open your exe, and scan the .resources files in it for your ico? – Kolichikov Oct 02 '15 at 20:30
0

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?

Community
  • 1
  • 1
svat
  • 136
  • 6
0

enter image description here

double click on Resources.resx in your solution explorer then select resource type and click on Add Resource -> Add Existing file