Mike Webb
Mike Webb

Reputation: 9003

In Visual Studio is there a way to change the Application Icon based on the build configuration?

Where I work we have a program that is used by our company. We then have another build of that same program that uses different data and different backgrounds, title text, etc. This all works fine, but since both are technically the same application the Application Icon is the same for both. We want separate icons for each build.

The Application icon is set in the project file: <ApplicationIcon>MyIcon.ico</ApplicationIcon>

Is there a way to have a different icon based on the build configuration? I know that the Condition attribute is not valid for the <ApplicationIcon> tag.

Upvotes: 2

Views: 2511

Answers (2)

Nicodemeus
Nicodemeus

Reputation: 4083

I know that the Condition attribute is not valid for the tag.

No you don't. Notice the parent <PropertyGroup /> tag? This indicates the ApplicationIcon tag is an MsBuild property so the Condition attribute would be valid in this case.

<PropertyGroup>
  <ApplicationIcon Condition=" '$(Platform)' == 'x86' ">x86.ico</ApplicationIcon>
  <ApplicationIcon Condition=" '$(Platform)' == 'x64' ">x64.ico</ApplicationIcon>
</PropertyGroup>

Heck, if your file names resolve to an MsBuild property value like they do above, you could infer the file name like so:

<PropertyGroup>
  <ApplicationIcon>$(Platform).ico</ApplicationIcon>
</PropertyGroup>

EDIT: Pretend the above uses and properly evaluates $(Configuration) property values rather than $(Platform)

Upvotes: 3

Keeler
Keeler

Reputation: 2150

I tried right-clicking a project, choosing Properties, and clicking the Application tab. This is where you can change the icon file. However, the Configuration and Platform dropdowns are disabled. This confirms that if you can have different icon files for different builds, it's not going to be the easy way.

If you do any scripting to customize your build, you could 'preprocess' your *.csproj file, setting ApplicationIcon based on the desired build, then build the project.

Upvotes: 0

Related Questions