I am creating a project for two different people and I would like to change the icon via define. For example:
#if customer1
//add code to select c:\path to resources\myimage1.ico for exe icon
#else
//add code to select c:\path to resources\myimage2.ico for exe icon
#endif
I know you can manually select which icon you want here:
https://msdn.microsoft.com/en-us/library/339stzf7.aspx
But the define way make sense for us using git so we don't have to keep reuploading someone else's image. We can simply just put the define and have it use that image. Thanks.
You can modify the csproj file so that you create different build configurations for the two customers. For example, you can do the following:
Unload the project by right-clicking on the project in the Solution Explorer within Visual Studio and clicking "Unload Project".
Right-click on your unloaded project and click "Edit "
Find the "ApplicationIcon" tag and replace it with two conditional PropertyGroups, like this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
<ApplicationIcon>netfol.ico</ApplicationIcon>
</PropertyGroup>
This will create a debug build configuration for Customer1 and Customer2.
- Do the same on your icon ItemGroup, also in the project file, like this:
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
<Content Include="netfol.ico" />
</ItemGroup>
- Find the PropertyGroup for the configuration, itself. It will have this line:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- Below this group, add groups for the debug configuration for your two new debug customer configurations, like this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug_Customer1\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug_Customer2\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Click Save.
Right-click on the project file in the Solution Explorer and click "Reload Project". Say yes if Visual Studio asks if you want to close the project file.
Now when you want to build for different customers, go to Build\Configuration Manager and select the customer-specific configuration.
- Repeat these steps to add release-specific configurations for each customer.