Korvo
Korvo

Reputation: 9714

How add icon to dotnet desktop (Windows) application?

I have only used the dotnet line commands, both to generate projects and to generate "solutions" (.sln), however I don't know if it is possible to use resource.rc directly withdotnet with something like:

MAINICON  ICON  "icon.ico"

The question is, how can I add with resource.rc (or other means) an icon for a standard .NET-core application?

Will I need any tools other than dotnet (CLI) for this?

Upvotes: 7

Views: 6848

Answers (1)

Korvo
Korvo

Reputation: 9714

Today I did a test and apparently the tag works on netcoreapp3.1:

<ApplicationIcon>nome.ico</ApplicationIcon>

Obviously the project has to be an application, in my case I created a "console" application like this:

mkdir projeto1
cd projeto1
dotnet new console

So I was generated projeto1.csproj, I opened it and edited this way:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <ApplicationIcon>nome.ico</ApplicationIcon>
  </PropertyGroup>

</Project>

So then I ran dotnet run and using both the c Debug and c Release flags (and publish also) this works, the example I did:

icon in csproj project for net core

So I ran dotnet build and got the desired one:

executable with icon

Upvotes: 21

Related Questions