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.
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
<Content Include="netfol.ico" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With