Change name of exe depending on conditional compilation symbol

Patrick picture Patrick · May 18, 2010 · Viewed 9.6k times · Source

Can you tell Visual Studio to output a different name of an exe file depending on if a specific conditional compilation symbol is set?

Answer

Fredrik Mörk picture Fredrik Mörk · May 18, 2010

If you load the .csproj file into a text editor, you can control the AssemblyName property:

<AssemblyName Condition="'$(Configuration)' == 'Debug'">WindowsFormsApplication9.Debug</AssemblyName>
<AssemblyName Condition="'$(Configuration)' != 'Debug'">WindowsFormsApplication9</AssemblyName>

Note though that this does not only change the file name, but the assembly name, which might mean trouble if you have other code referencing the assembly.

I never did this myself, so I can't really say how good or bad the idea is.