Visual Studio 2010: ApplicationIcon

by Aaron 30. June 2011 02:45

I recently had need to associate a different icon to my C# project based on the selected configuration (i.e. Debug, Release, SomeCustomConfigurationYouCreatedToBeClever).

I did the standard thing of right-click on the project in the Solution Explorer, select Unload Project. Then I again, right-click on the project and choose Edit MyFancyProject.csproj. ApplicationIcon was easy to find.

I tried several ways of setting the icon. I tried a handful of ApplicationIcon nodes with Condition attribute set to " '$(Configuration)' == 'SomeCustomConfigurationYouCreatedToBeClever' ".  I added a line for each of the different configurations.

I saved and reloaded the project into Visual Studio.  The icon it showed wasn't the icon for the selected configuration.  I checked the syntax in the CSPROJ file with no luck.  I changed it to a Choose element with multiple conditions to add a new PropertyGroup with the appropriate icon.  Again, Visual Studio showed me the wrong icon.

Finally, I added the ApplicationIcon element to each of the $(Configuration)|$(Platform).  Still, didn't work!

I decided to just try compiling the application to see what icon was embedded and displayed for the executable after a build.  The icon was right!

The moral of this story is that Visual Studio doesn't process the conditions set in the CSPROJ file, but will process it during the build.

Tags: , , , ,