9

I'm developing Windows Application using Visual Studio 2013 and F# but I can't change default application icon.

I have tried to create a C#-WPF application for font-end, it work. But I don't want to use C# for font-end.

I also tried resource hacker after building my application, but it is just not working.

Abel
  • 56,041
  • 24
  • 146
  • 247
  • possible duplicate of [Embed an application icon using WPF and F#](http://stackoverflow.com/questions/7500164/embed-an-application-icon-using-wpf-and-f) – Ruben Bartelink Dec 06 '14 at 06:08

3 Answers3

11

The application icon is the image that appears in Windows Explorer when viewing the EXE file. To set the application icon of an F# Windows Application:

  1. Create a text file with an *.rc extension.

  2. Add one line to the *.rc file (substituting the name of your icon file, of course): 1 ICON "icon.ico".

  3. Compile the *.rc file with rc.exe into an *.res file.

  4. In Visual Studio, in the property page for your *.exe project, set the *.res file as your project's "Resource file."

While we are on the topic, the icon that appears in the Windows task bar comes from the main window icon. It can be set like this:

  1. Include the icon in the project as a Resource (not an EmbeddedResource).
  2. In your main window XAML, reference the icon using the assembly path.

Sample:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Icon="/MyAssemblyName;component/MyPathToIcons/Logo.ico">
Abel
  • 56,041
  • 24
  • 146
  • 247
Wallace Kelly
  • 15,565
  • 8
  • 50
  • 71
  • 2
    Useful addition here: you need to install the Visual C++ option in VS for this to work as rc.exe is only available when that is installed. Took me a fair while to work this was why I couldn't find rc,exe on my system. Once installed, it was then a doddle to follow your instructions. – David Arno May 13 '16 at 08:22
  • I can't remember ever having needed Visual C++ in order to get rc.exe on the machine. I checked my VS install now, and C++ is not checked anywhere. – Bent Tranberg Feb 16 '23 at 11:26
  • Today we can simply use ApplicationIcon in an SDK-style project, with just an icon file. For console apps, this icon is used everywhere - on file, in taskbar, in console window. Possibly dependent on having a later version of Windows. – Bent Tranberg Feb 16 '23 at 11:43
-1

I assume you are trying to set the icon of a command-line application. This isn't possible. Only desktop applications have icons. Console applications have no window, hence no icon. You can specify an icon when you create a shortcut to the application (eg during setup) but that has nothing to do with the application itself.

Visual Studio 2013 contains only an F# console application. If you want to create a WPF application you should use a different template like Daniel Mohl's F# Empty Windows App template.

The template doesn't provide the same project settings as a C# WPF project, but you can use all WPF mechanisms to set the icon, eg. by storing the application's icon in the Resources, setting a Window's Icon property etc

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • 2
    i'm developing Windows Application(WPF) not command line application. I'm asking how can i set application icon (exe icon) on F# Wpf Windows Application. – Umut Karakoç Nov 11 '14 at 07:00
  • 3
    Actually, it _is_ possible, the first icon resource, numerically, in the executable, is used by Windows to display in Explorer (you can select it in Properties for Console C# applications or use Wally's approach for F# applications). It doesn't matter whether it is a console application or not. Unless you mean old 16 bit applications or `*.com` programs. – Abel Jun 01 '15 at 11:14
-1
Title="MVVM and XAML Type provider" Height="200" Width="400" Icon="C:\Users\Honu\AppData\Local\Microsoft\Windows\INetCache\IE\4JGLDZVB\favicon8C20UVN3.ico">

This displays a Lambda symbol Icon ...

I used Daniel Mohl's F# Empty Windows App template. Just added the Icon= etc

Hope this helps

Art Scott
  • 193
  • 1
  • 2
  • 8
  • 1
    This is the same as the original answer, second part, except that the original answer uses a relative path (never use absolute paths in projects, it breaks as soon as you move it)... – Abel Jun 01 '15 at 11:18