Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional file compilation in Visual Studio and .NET

I am developing a software tool for my company. I am using Visual Studio, C# and targeting .NET 4.0. One of requirements is the software will be released in three versions (limited, standard and extended). There are several interns/trainee in my company as well as some regular employees and managers. And each group will be given other version of the software. The limited version for interns, the standard one for employees and the extended one for managers. Theese are requirements given to me. Moreover, it must be one executable file (no dll files) for each version.

So, I created one project containing a group of files which will be conditionally compiled and built. In the main program I can use the directive #if and/or the [Conditional] attribute to instantiate only required classes depending on current configuration.

But files which are currently unnecessary are compiled and built anyway. And the created executable file contains all the code from those files which is undesirable and does not meet requirements given to me. Each executable file should contain only code needed for the target group of employees. (This is because of security reasons.)

So my question is how can I exclude a group of files from compilation process depending on current configuration?

like image 721
Victor Avatar asked Oct 08 '13 11:10

Victor


1 Answers

What you trying to achieve is developing a software product-line(1). There is lots of research going on in this field. The current solutions are very limited and most of them are already mentioned in the comments:

  • use the #if compiler directive to ignore files that are not required (CodeNaked)
  • manage multiple solution files (Weyland Yutani)
  • use feature ide (2) or some other tools/helpers for feature orientation (3) and develop those advanced versions as features (this will require some additional time to get into)
  • Of course you can use a combination of the above

You can also develop those 3 applications completly independent which is not what you want. But also note that you can extract common functionality in libraries and then use ILMerge(4) to get back to your single .exe file for each version.

I think those are your options and you should choose the best combination for your situation. If your three applications are very similar and share lots of functionality I would choose "#if" or multiple solutions files (as you are limited to 3 versions only). If the versions differ a lot maybe ILMerge and extracting common functionality is a better way to go. I don't know if feature orientation is production ready so I mentioned them for completness sake.

And don't forget the comment of CodeNaked: Your security should really not depend on the code available to the user...

like image 147
matthid Avatar answered Sep 19 '22 13:09

matthid