0

I have a C# (.Net 4.0) WPF desktop application, which is builds to and distributed as a single-file executable. We're using Visual Studio 2013.

We now have a situation where we need to create a separate version of this application, that is almost identical but has different "branding" - mainly a single graphic for a logo and a change to a few bits of text.

I'd prefer not to have to maintain two different projects: is there any way to change the logo and text fields to read in some kind of variable or parameter at build-time, so that ultimately two different single executables are created: functionally identical but with different logos and text?

KenD
  • 5,280
  • 7
  • 48
  • 85
  • There are many ways to do this, conditional compilation, create a new configuration, or have multiple .exe projects and use a shared project for the common elements - to name three. – AnthonyLambert Sep 26 '14 at 14:36
  • If it were me, I'd have a _Theme_ class to include the logo image (URI or otherwise) and the text. The class can be serialized to an XML and then read at runtime. For every variation of the app it'd simply be another XML file. – bdimag Sep 26 '14 at 16:54
  • Unfortunately I need to keep the app as a single executable file, with no "support" files or any other dependencies. It's a long story ... :/ – KenD Sep 26 '14 at 18:00
  • I did miss that -- I wonder if it'd be useful setting up different configurations and using `conditional compilation symbols` (e.g., #IF DEBUG -- #IF CUSTOMER1 -- #IF CUSTOMER2) http://stackoverflow.com/questions/507704/will-if-release-work-like-if-debug-does-in-c (answer) – bdimag Sep 26 '14 at 19:25
  • see https://stackoverflow.com/q/10086591/492 – CAD bloke Jan 24 '22 at 21:03

2 Answers2

1

If you are using Visual Studio 2013 I'd look at the new Shared Projects feature.

Basically you would then have two .exe projects with just the pieces that are different and then they would both reference the shared parts defined in the shared project.

The link above should give you a few examples, they use it for Windows 8 applications but it will work for any type including WPF.

AnthonyLambert
  • 8,768
  • 4
  • 37
  • 72
1

It depends on the level of customisation. If your just swapping out logos, colours and possibly fonts - putting them as resources in a resource dictionary and then referencing them using DynamicResource binding...

<Label Content="{DynamicResource CompanyName}"\>

You can then do a couple of things...

First option, create duplicate resource dictionaries for each branding and load the appropriate one on launch - possibly based on a key value in app.config. [enter link description here][Stackoverflow suggestion here].

The second option, is a helper class to set the values of your resources in code behind.

Just a couple of suggestions I hope might help.

kidshaw
  • 3,423
  • 2
  • 16
  • 28