468,510 Members | 1,712 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

.NET dynamic assembly with a custom icon?

15
I've been recently working on application that generates .net assemblies on-the-fly using the methods in System.Reflection.Emit. It works well, but i would like to also change the icon of my freshly baked exe, so it would not appear the default icon.
The idea is to be able to embed the icon in the assembly, (i guess as a resource) and make that icon a default assembly icon. I am not talking about window icon that can be set on any window, but the icon of the executable.

Thanks in advance
Oct 2 '08 #1
4 2137
joedeene
583 512MB
maybe this will help you, a simple search on google.com is always useful...

Link 1

joedeene
Oct 2 '08 #2
l034n
15
Thanks for the reply joedeene. Well, i did search on google for hours before i posted it here with no luck. The problem is that i need this done with System.Reflection.Emit, so it should be dynamic assembly generation on-the-fly with AssemblyBuilder. I know very well how to embed resources in the current assembly (or in it's res/resource file). The trouble comes when i want to make some of those embedded icons to be the actual exe icon once it's generated using the AssemblyBuilder (pardon the redundancy).
I have tried embedding icons in VS and setting one of them as assembly icon (which always works doing it with VS IDE), so then I checked the generated assembly using ildasm, but i just can't seem to find the connection between the icon and the assembly (where the icon is actually assigned to the assembly). Of course, i see the icon in the Resources, but i don't see any piece of code where it actually is referenced, hence i asked if anyone has any idea of how that can be done.
Oct 2 '08 #3
Plater
7,872 Expert 4TB
I too attempted to search where it keeps track of what icon to use for an assembly and could not find it. I don't think it's assigned until the "linker" stage when the exe is produced? It seems to be in the project file itself.

So here is what I found for differences:
Expand|Select|Wrap|Line Numbers
  1. //Using an icon in the resx resource file
  2. <PropertyGroup>
  3.   ...
  4.   <Win32Resource>
  5.   </Win32Resource>
  6.   <ApplicationIcon>Resources\testicon.ico</ApplicationIcon>
  7. </PropertyGroup>
  8.  
  9. <Compile Include="Properties\Resources.Designer.cs">
  10.   <AutoGen>True</AutoGen>
  11.   <DependentUpon>Resources.resx</DependentUpon>
  12.   <DesignTime>True</DesignTime>
  13. </Compile>
  14.  
  15. <ItemGroup>
  16.   <Content Include="MCI_ERROR.txt" />
  17.   <None Include="Resources\testicon.ico" />
  18. </ItemGroup>
  19.  
Expand|Select|Wrap|Line Numbers
  1. //using win32resource res file
  2. <PropertyGroup>
  3.   ...
  4.   <Win32Resource>C:\Projects\testsolution\testproject\ResTempl1.res</Win32Resource>
  5. </PropertyGroup>
  6.  
  7. <Compile Include="Properties\Resources.Designer.cs">
  8.   <AutoGen>True</AutoGen>
  9.   <DependentUpon>Resources.resx</DependentUpon>
  10. </Compile>
  11.  
  12. <ItemGroup>
  13.   <Content Include="MCI_ERROR.txt" />
  14. </ItemGroup>
  15.  
Maybe something there will help you?
Oct 3 '08 #4
l034n
15
Thanks for the pointer Plater. That is some progress in the right direction. Although i still can't seem to put all the pieces together, it was helpfull. I just wonder if i am going to solve this the way i am doing it (making assembly with Emit) and if it's even possible. There is a switch in csc.exe (/win32icon:<file>) which can be used to assign an icon, but then the whole point of using Emit is to make the assembly dynamically, not to redistribute c# compiler along with the program that generates dynamic assemblies, and then dump a source file and call the compiler (which as a last resort can be done, but i wouldn't go for it... yet). Then, i check ilasm switches and i don't see anything like that, and it comes clear that using ilasm.exe the icon can not be set either. So, it must be possible to set it somehow with IL, or the tools aren't mature enough yet.
I wouldn't like to think that the guys in M$ code the Emit namespace (which is really a great one) but made it in a way that every assembly generated this way will have the default icon. It just doesn't make sense.
I'll keep digging into this and if i find a solution, i'll post it here... until than maybe someone will give me a hand :-)
Oct 3 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Stephen Gennard | last post: by
reply views Thread by Eric Marthinsen | last post: by
6 posts views Thread by Philipp Schumann | last post: by
2 posts views Thread by Dexter | last post: by
15 posts views Thread by EDBrian | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.