Fletcher Johnson
Fletcher Johnson

Reputation: 58

How can I identify the name of the icon file used in a C# application?

I have a C# WPF application. It has two icon files as resources - one for use when creating a release build, and the other for test builds. It is currently using 4.7.2 - but I am are planning to migrate it to .NET Core soon.

When I am generating a build, I set the icon file via the Properties-Application page.

Since I can't find a way to conditionally set the desktop icon file reliably when building, I thought I would simply check the icon file at runtime to see if it is the correct one for the build type. I do not want to have the wrong icon file used.

Why do I care? There are a number of users who might have the test and live version on their desktop at the same time. I want to make sure that the test versions can not be confused with the live version.

It may not seem like much, but often, support people remote in and most of them won't know about the test version - hence the need to avoid any confusion.

If you have a better way to set the desktop than setting the icon at build time, that would be appreciated too.

I can get the icon using ExtractAssocatedIcon() - but that doesn't indicate the name of the icon file.

Upvotes: 0

Views: 237

Answers (1)

spire2985
spire2985

Reputation: 96

You could do the following to set the icon at build time.

Here are some steps:

  1. Create your project and add your .ico files.

    WPF Project with two .ico files

  2. Right click the project and select Unload Project.

    Unload the project

  3. Right click the unloaded project and select Edit Project File.

    Edit Project File

  4. Inside of the project file there will be <PropertyGroup> xml tags for your various builds.

    Project File PropertyGroup example

    Set the <ApplicationIcon> xml element for each build configuration.

    Set ApplicationIcon in each build configuration

Now when you run the build in either Debug or Release the .ico file that is used will change.

Example of changed ico with build

Upvotes: 1

Related Questions