tags:

views:

174

answers:

3

I have a .NET app that I produce several different versions - the exact same app but with different 'branding' (splash screen, name, etc.). I have all of those differences outside the main executable so they're picked up at runtime, however I can't do this with the program icon because it's baked into the .exe.

I'd like to avoid making lots of different projects just for the icon. Is there a way I can modify the icon for an already built .net exe? I have a feeling Ildasm.exe and Ilasm.exe might be handy here, but I'm not sure what to do with the disassembled bits to change the icon ready to feed it into Ilasm.

Should I just use a script that modifies the original project file to use a new icon and re-build the whole thing?

Or maybe I'm going about this entirely the wrong way, any suggestions would be appreciated.

+1  A: 

You can leave you exe "unbranded" and keep your icons as separate files. During deployment, use the appropriate icon for the application shortcuts.

Tormod Fjeldskår
This is the option I was leaning towards, but I've ended up needing to change more than just the icon. So I'm now using the CodeDom to generate a stub exe with all the correct bits that will just call into the 'real' Main method.
Wilka
A: 

Check out ResHacker.exe or XN Resource Editor. I haven't used XN Resource Editor but have used ResHacker to change the icon resource in a PE.

Arnshea
A: 

I ended up needing to change more than just the icon. So I'm using the CodeDom to generate a stub exe with all the correct bits that references the 'real' starting assembly and just calls it's version of 'main'.

Setting the correct icon for this was just a matter of using

var compilerParams = new CompilerParameters
{
  GenerateExecutable = true,
  CompilerOptions = string.Format("/target:winexe /win32icon:\"{0}\"", iconPath)
  // ... other options ...
}

when calling:

var codeProvider = new CSharpCodeProvider();
codeProvider.CompileAssemblyFromSource(compilerParams, new[] { sourceCode });
Wilka