Embedding an F# Executable Icon September, 2009
VB.NET and C# have a convenient way to embed an executable icon in the Application properties. As of v18.104.22.168 F# does not. Nevertheless its fairly simple to add one, albeit with a few additional steps.
1) First you'll need to install the .NET 2.0 Framework SDK.
2) Create a resource script as follows (Including the number one, that's not a line number... Also replace your icon name) and save it as AppIcon.rc (Or whatever):
1 ICON MyAppIcon.ico
3) Next compile the script with the resource compiler utility as follows (Make sure the icon file is in the same folder as the resource script. Also remove the " (x86)" from the resource compiler path if your working in a 32 bit OS):
"C:\Program Files (x86)\Microsoft.NET\SDK\v2.0\Bin\rc" AppIcon.rc
This will create a win32 resource file called AppIcon.RES in the same folder. Once this is done you wont have to do this again unless you want to change the icon (So you can delete the .rc file if you want at this point or hang onto it in case you want to change the icon in the future).
4) Now we need to tell the F# compiler to include the resource file in the resulting assembly. You'll notice that there is a textbox under the Application properties tab for a resource file, but this is for a .NET resource file not a win32 one. So we'll have to specify our win32 resource file with a compiler flag under the Build properties tab, in the "Other flags" textbox using the "—win32res" compiler flag:
Now when we compile, the resource will be included in the resulting file and the assembly icon will show up in Windows Explorer.
On a side note. you'll probably want to include different sizes of icons for the different views in Windows Explorer (Detail, small, etc). Most icon or image libraries ship with multiple sizes of all their images. Instead of using a single icon file (Which will only give you one icon size in Windows Explorer and look distorted in other views) you can create a multi-icon file with different sizes of the same icon. Windows explorer will automatically pick the appropriate size for the current view (Which looks a lot better!). One free tool you can use to create mutli-icon files is @icon sushi. To do this open icon sushi and drag all the different sizes of images (They can be almost any image format not just icons) onto the window. Then select them all and right-click "Save|Save as Multiple Icon..." click "File|Save as Multiple Icon...". Using this type of file as your icon resource will result in what is seen in the image above where there are multiple icon resources of different sizes for Explorer to choose from.