I'll suggest to keep away from conditional compilation. because they create "Dead Code", meaning code that be in place but doesn't compile(just like comments).
It is completely fine if you're just changing Assembly Titles, etc but then if you're changing a feature based on compilation argument you should think of a better way.
Assume you have
private void SomeMethod()
{
//Some code
#if CCA
DoSomething();
#endif
}
private void DoSomething()
{ }
So what happens when you're refactoring your codebase and changed DoSomething
to DoSomethingInteresting
when CCA
switch is turned off. What happens? You have broken your code. but still it will compile, you'll not realize it till you turn CCA
switch on. Brittle isn't it?
I'll suggest you to move all the business logic, UI, etc in a library(dll) and then create a "BootStapper" project which is an executable which refers that dll and starts the application.
create a static class namely ApplicationConfig
or similar like this; Set the necessary properties from bootstrapper itself.
public class ApplicationConfig
{
public static string VersionText { get; set; }
}
Then you can simply do
myLabel.Text = ApplicationConfig.VersionText;
What benefits you get?
- You can change Assembly Titles, etc
- You can change Icon
- You eliminated brittle code
- etc
What is the dis advantage
- You need many bootstrapper projects (that's fine)
- You compile the feature to someone which they don't need