Reputation: 81
I have a web application developed using a mixture of ASP.NET webforms and MVC 5. I need to build different versions of the application, say Basic, Deluxe and Premium, each of these versions will have different features. I know that preprocessor directives is something C# offers for conditional building and creating different versions of an application.
In my case, my classes shouldn't include a method, namespace or a property depending on the application version built, also some of the dlls shouldn't be included depending on the application version, the same theory applies to the front end code as well say MVC code.
Any good directions on developing this will be much appreciated.
Upvotes: 1
Views: 325
Reputation: 2878
You may use the following approach:
public bool SomeMethod()
{
#ifdef BASIC
raise new Exception("this method is available in Deluxe version only!");
#endif
#ifdef DELUXE || PREMIUM
; // do some work available for deluxe versions only
#endif
}
Debug
Release
Debug BASIC
Release BASIC
Debug DELUXE
Release DELUXE
Debug PREMIUM
Release PREMIUM
This will also result having output folders for different versions (you may adjust them in the configuration's properties).
del PremiumDll.dll
Upvotes: 1
Reputation: 86789
Its going to be very difficult to maintain 3 different versions of an application using #if
and #endif
sections. Personally I would avoid this at all costs and instead use traditional runtime methods to control the differences between the 3 editions.
If it is 100% necessary that code only be shipped to users who are licensed for it then you should put that code in a separate assembly, possibly using some sort of plugin architecture.
Upvotes: 0
Reputation: 157108
Depending on your functionality and if you host it yourself, you could simply have a license system that sets the edition to use.
In your application (in your ASPX and MVC code) you could check against this license (with an <% if ...
for example) to know whether to enable or disable a button, a part of a form, an action, etc.
You could store this licenses in a database, even on a per-user basis, or in the app.config
settings.
If you have an application that is out of your control, you still can use this licensing method, but you need to check it against an external source. There are some tools out there to provide you with licensing (and optionally obfuscation).
Upvotes: 1