How to use Application properties to enforce a correct version for your add-in

Sometimes you need your add-in to operate only in the presence of a particular Update Release of Revit due to the presence of specific fixes or compatible APIs.

Properties of Application make it possible to check for specific versions of Revit. While the property VersionNumber will return a string representing the primary version number, the VersionBuild property will return the internal build number of the Autodesk Revit application.

Another useful property is the Application.SubVersionNumber property. It returns a string representing the major-minor version number for the Revit application such as "2018.0.0". This string is updated by Autodesk for all major and minor updates. Point releases (such as 2018.1.0) may have additional APIs and functionality not available in the initial customer release (such as 2018.0.0). Add-ins written to support initial releases will likely be compatible with subscription updates, but add-ins using new features in subscription updates would not be compatible with the initial releases.

The following sample code demonstrates a technique to determine if the Revit version is any Update Release after the initial known Revit release.

Code Region: Use VersionBuild to identify if your add-in is compatible

public void GetVersionInfo(Autodesk.Revit.ApplicationServices.Application app)
{ 
   // 20110309_2315 is the datecode of the initial release of Revit 2012 
   if (app.VersionNumber == "2012" && 
       String.Compare(app.VersionBuild, "20110309_2315") > 0)
   {
       TaskDialog.Show("Supported version", 
                      "This application supported in this version.");
   }
   else
   {
       TaskDialog dialog = new TaskDialog("Unsupported version.");
       dialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
       dialog.MainInstruction = "This Revit 2012 application is supported in UR1 and later releases.";
       dialog.Show();
   }
}