How to change the default icon inside of application? #797

Closed
opened 2026-01-29 16:48:54 +00:00 by claunia · 5 comments
Owner

Originally created by @ZedZipDev on GitHub (Jun 2, 2022).

I'd like to change the default Electron.NET icon with my own. How can I do it?
I have tried in _Host.cshtml

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Database App</title>
    <base href="~/" />
   <link rel="icon" type="image/x-icon" href="favicon2.ico" />

It does not work.

Ok, then I did it in the Startup.cs

       private async void CreateWindow()
        {
            // - original 
            //var window = await Electron.WindowManager.CreateWindowAsync();

            //window.OnClosed += () => {
            //    Electron.App.Quit();
            //};

            // -----------new

            string icon = "favicon2.ico";
			var window = await Electron.WindowManager.CreateWindowAsync(
				new BrowserWindowOptions
				{
					Icon = icon
				});

			window.OnClosed += () => {
				Electron.App.Quit();
			};
        }

Again: does not work.
What I do wrong? How to change the default icon?

Originally created by @ZedZipDev on GitHub (Jun 2, 2022). I'd like to change the default Electron.NET icon with my own. How can I do it? I have tried in _Host.cshtml ``` <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Database App</title> <base href="~/" /> <link rel="icon" type="image/x-icon" href="favicon2.ico" /> ``` It does not work. Ok, then I did it in the Startup.cs ``` private async void CreateWindow() { // - original //var window = await Electron.WindowManager.CreateWindowAsync(); //window.OnClosed += () => { // Electron.App.Quit(); //}; // -----------new string icon = "favicon2.ico"; var window = await Electron.WindowManager.CreateWindowAsync( new BrowserWindowOptions { Icon = icon }); window.OnClosed += () => { Electron.App.Quit(); }; } ``` Again: does not work. What I do wrong? How to change the default icon?
claunia added the bug label 2026-01-29 16:48:54 +00:00
Author
Owner

@ggomarighetti commented on GitHub (Jun 9, 2022):

Resume

The configuration to establish which will be the icon of your application as well as its relative location, is in electron.manifest.json.

In a default configuration you must go to line 18 of your configuration, position yourself at the end of the configuration and paste the attached code.

There you will have an idea to establish the relative directory of the icon that you want to use, in case of linux and mac I believe that it should be .png and in case of windows .ico.

Code

    "win": {
      "icon": "../../../Build/alphagob.ico"
    },
@ggomarighetti commented on GitHub (Jun 9, 2022): #### Resume The configuration to establish which will be the icon of your application as well as its relative location, is in electron.manifest.json. In a default configuration you must go to line 18 of your configuration, position yourself at the end of the configuration and paste the attached code. There you will have an idea to establish the relative directory of the icon that you want to use, in case of linux and mac I believe that it should be .png and in case of windows .ico. #### Code ``` "win": { "icon": "../../../Build/alphagob.ico" }, ```
Author
Owner

@Taster-git commented on GitHub (Jun 29, 2022):

Resume

The configuration to establish which will be the icon of your application as well as its relative location, is in electron.manifest.json.

In a default configuration you must go to line 18 of your configuration, position yourself at the end of the configuration and paste the attached code.

There you will have an idea to establish the relative directory of the icon that you want to use, in case of linux and mac I believe that it should be .png and in case of windows .ico.

Code

    "win": {
      "icon": "../../../Build/alphagob.ico"
    },

How to do it for Linux ?????

@Taster-git commented on GitHub (Jun 29, 2022): > #### Resume > The configuration to establish which will be the icon of your application as well as its relative location, is in electron.manifest.json. > > In a default configuration you must go to line 18 of your configuration, position yourself at the end of the configuration and paste the attached code. > > There you will have an idea to establish the relative directory of the icon that you want to use, in case of linux and mac I believe that it should be .png and in case of windows .ico. > > #### Code > ``` > "win": { > "icon": "../../../Build/alphagob.ico" > }, > ``` How to do it for Linux ?????
Author
Owner

@Jamie-Cappel-Chiron commented on GitHub (Jul 31, 2022):

    "win": {
      "icon": "../../../Build/alphagob.ico"
    },

Hmm.. Have tried the following above solution to no effect.

@Jamie-Cappel-Chiron commented on GitHub (Jul 31, 2022): ``` "win": { "icon": "../../../Build/alphagob.ico" }, ``` Hmm.. Have tried the following above solution to no effect.
Author
Owner

@jamieyello commented on GitHub (Jan 14, 2023):

I've tried fixing this for several days straight, I've tried putting the icon everywhere and I'm certain this must be some kind of bug.

I've tried the recommended

  "win": {
    "icon": "../../../build/icon.ico"
  }

Then this (which worked for someone)

  "win": {
    "icon": "bin/build/icon.png"
  }

Still "application icon not set". I've tried converting it to a PNG as well. As a last-ditch effort, I have edited the compiled exe to swap out the icon, but I worry that may set off security warnings when deployed.

I've double, triple, and quadruple-checked to ensure that the path names are valid relative to the directory the console says it's running from. I've compared my project to the SilverR one as well, and I can't tell any difference.

So I guess my last ditch effort should be replacing the default ElectronNET builder icon in the builder program files themselves.

Here's my full electron.manifest.json

{
  "executable": "Chiron.Pelion.Vault.Electron",
  "splashscreen": {
    "imageFile": "/wwwroot/Pelion_Icon.ico"
  },
  "name": "Chiron.Pelion.Vault.Electron",
  "author": "",
  "singleInstance": false,
  "environment": "Production",
  "build": {
    "appId": "com.Chiron.Pelion.Vault.Electron.app",
    "productName": "Pelion Vault",
    "copyright": "Copyright © 2022. Chiron Cryptography, Inc. All Rights Reserved.",
    "buildVersion": "0.7.8",
    "compression": "maximum",
    "directories": {
      "output": "../../../bin/Desktop"
    },
    "extraResources": [
      {
        "from": "./bin",
        "to": "bin",
        "filter": [ "**/*" ]
      }
    ],
    "files": [
      {
        "from": "./ElectronHostHook/node_modules",
        "to": "ElectronHostHook/node_modules",
        "filter": [ "**/*" ]
      },
      "**/*"
    ]
  },
  "win": {
    "icon": "../../../build/icon.ico"
  }
}
@jamieyello commented on GitHub (Jan 14, 2023): I've tried fixing this for several days straight, I've tried putting the icon everywhere and I'm certain this must be some kind of bug. I've tried the recommended ``` "win": { "icon": "../../../build/icon.ico" } ``` Then this (which worked for someone) ``` "win": { "icon": "bin/build/icon.png" } ``` Still "application icon not set". I've tried converting it to a PNG as well. As a last-ditch effort, I have edited the compiled exe to swap out the icon, but I worry that may set off security warnings when deployed. I've double, triple, and quadruple-checked to ensure that the path names are valid relative to the directory the console says it's running from. I've compared my project to the SilverR one as well, and I can't tell any difference. So I guess my last ditch effort should be replacing the default ElectronNET builder icon in the builder program files themselves. Here's my full electron.manifest.json ``` { "executable": "Chiron.Pelion.Vault.Electron", "splashscreen": { "imageFile": "/wwwroot/Pelion_Icon.ico" }, "name": "Chiron.Pelion.Vault.Electron", "author": "", "singleInstance": false, "environment": "Production", "build": { "appId": "com.Chiron.Pelion.Vault.Electron.app", "productName": "Pelion Vault", "copyright": "Copyright © 2022. Chiron Cryptography, Inc. All Rights Reserved.", "buildVersion": "0.7.8", "compression": "maximum", "directories": { "output": "../../../bin/Desktop" }, "extraResources": [ { "from": "./bin", "to": "bin", "filter": [ "**/*" ] } ], "files": [ { "from": "./ElectronHostHook/node_modules", "to": "ElectronHostHook/node_modules", "filter": [ "**/*" ] }, "**/*" ] }, "win": { "icon": "../../../build/icon.ico" } } ```
Author
Owner

@jamieyello commented on GitHub (Jan 14, 2023):

Ok, so I found out that the "win" json object was in the wrong place in my manifest file.

In the above .json file, after moving the "win" section to be inside the "build" section it finally used the icon I wanted. So it was my fault, after all. No bug.

  "build": {
    "appId": "com.Chiron.Pelion.Vault.Electron.app",
    "productName": "Pelion Vault",
    "copyright": "Copyright © 2022. Chiron Cryptography, Inc. All Rights Reserved.",
    "buildVersion": "0.7.8",
    "compression": "maximum",
    "directories": {
      "output": "../../../bin/Desktop"
    },
    "win": {
	  "icon": "../../../build/icon.ico"
    },
@jamieyello commented on GitHub (Jan 14, 2023): Ok, so I found out that the "win" json object was in the wrong place in my manifest file. In the above .json file, after moving the "win" section to be _inside_ the "build" section it finally used the icon I wanted. So it was my fault, after all. No bug. ``` "build": { "appId": "com.Chiron.Pelion.Vault.Electron.app", "productName": "Pelion Vault", "copyright": "Copyright © 2022. Chiron Cryptography, Inc. All Rights Reserved.", "buildVersion": "0.7.8", "compression": "maximum", "directories": { "output": "../../../bin/Desktop" }, "win": { "icon": "../../../build/icon.ico" }, ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#797