i486
i486

Reputation: 6573

Different icons for different configurations (WinForm)

I have a project with 2+ release configurations. They are similar with small differences. I want to put different icons for both project variations. The icon for main form is changed programmatically. But the icon used for exe file is set from project properties (Visual Studio 2010) and in Application tab the icon is global for all configurations (e.g. Debug, Release A, Release B). Is there a way to set icon-1 for Release A and icon-2 for Release B? The only solution for the moment is to use icon with the same name and define pre-build event to replace working icon with icon-1 and icon-2 files.

Upvotes: 0

Views: 576

Answers (1)

Jack J Jun- MSFT
Jack J Jun- MSFT

Reputation: 5986

As others suggested, you can use MSBuild properties to set different icons for different configurations.

You can edit your .csproj file and add the ApplicationIcon to the PropertyGroup.

Like the following:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <ApplicationIcon>D:\1.ico</ApplicationIcon>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <ApplicationIcon>D:\2.ico</ApplicationIcon>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release A|AnyCPU'">
      <ApplicationIcon>D:\3.ico</ApplicationIcon>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release B|AnyCPU'">
        <ApplicationIcon>D:\4.ico</ApplicationIcon>
    <OutputPath>bin\Release B\</OutputPath>
  </PropertyGroup>
  

Note: I assume that your default platform is AnyCPU. If you want to set the icon for different platforms, you can use the same way as the above code.

Result: enter image description here

Upvotes: 3

Related Questions