Angel Roche
Angel Roche

Reputation: 81

Building different versions of an application in .NET

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

Answers (3)

Eugene
Eugene

Reputation: 2878

You may use the following approach:

  1. It's not good to have different API of your application in different versions of your product. Why? Because your user may easily upgrade to Premium or Deluxe versions without recompiling the app if you provide the same API. You should better use the same API but lock methods available for Deluxe and Premium users. Use defines in your code to lock or unlock the functionality, like this:
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
}
  1. Create 2 configurations for each version of your application, one based on "Debug" and another one based on "Release" configuration of your product so you may test different versions in both Release and Debug modes. So you may have something like this:
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).

  1. Modify "Post-build event" command line code (in Project - Properties - Build Events) to remove unnecessary dll files from the output folder, like this:
del PremiumDll.dll 

Upvotes: 1

Justin
Justin

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

Patrick Hofman
Patrick Hofman

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

Related Questions