How can I change the executable filename and icon for different build configurations?

Viewed 146

I want to have a different icon and executable file name for different builds of my WPF application. The reason is that I have two different version of the app which are slightly different (just a few items disabled, color changes etc) So I used two different build configurations and the App.config transforms to do that for example in my transform I have several transformations like this

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
  <appSettings xdt:Transform="Replace"> 
    <add key="appTitle" value="Application Name 2"/> 
    <add key="appIcon" value="Icons\appplicationIcon2.ico"/> 
  </appSettings> 
</configuration> 

And then in my app I read the configuration setting for that property, appTitle or appIcon, and I perform some cosmetic or other changes to the app based on that.

But can I also use this to apply a change on the application icon itself (the one that gets embedded in the EXE, or the name of the EXE file?

1 Answers

In addition to the answer linked here https://stackoverflow.com/a/32977405/1462656 To change the application executable name on compile you must add the following as well to the property group

<AssemblyName>Name For Executable</AssemblyName>

So the property group should have these two additions

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Your Configuration Name|x64'">
    <ApplicationIcon>Icons\YourIconFilename.ico</ApplicationIcon>
    <AssemblyName>Your Application Name</AssemblyName>
    ...
  </PropertyGroup>

EDIT: I noticed that this does not have any effect on the Product Name or File Description as seen when you right click and view property details of the executable from File Explorer. To also have different values for Product and File Description do he following

  • Add Conditional Compilation Symbols in the Build properties for the project configuration
  • In the AssemblyInfo.cs do something like this
    #if APPONE
        [assembly: AssemblyTitle("App 1")]
    #else
        [assembly: AssemblyTitle("App 2")]
    #endif
Related