Umbraco V7/ Belle Compatibility Helper
Now that Umbraco 7 alpha is out http://umbraco.com/follow-us/blog-archive/2013/9/27/umbraco-7-alpha-is-here.aspx you can start testing your packages.
Here is a little helper that you can use in your Umbraco projects to identify if you are running v7 or older/newer (useful if you have a package you want to upgrade and want to perform a different action depending on the Umbraco version)
public class CompatibilityHelper
{
public static bool IsVersion7OrNewer
{
get
{
var retval = true;
try
{
typeof(umbraco.uicontrols.CodeArea).InvokeMember("Menu",
BindingFlags.GetField, null, new umbraco.uicontrols.CodeArea(), null);
}
catch (MissingFieldException e)
{
retval = false;
}
return retval;
}
}
}
It basically checks if the umbraco.uicontrols.CodeArea has the Menu field (which was added in v7 so if that fails it’s an older version)
Would be good to add some caching to it…
You could also use the UmbracoVersion class which returns a proper Version object:

var version = Umbraco.Core.Configuration.UmbracoVersion.Current;
- Morten
@Morten, yeah but when did that one get added?
In one of the early version 6 releases. Don’t remember exactly which one. So obviously not available in v.4.x.
Hi Tim,
Try Catch is quite expensive to use. I’m using a check on the version also
public static bool SupportsBelle
{
get
{
return GlobalSettings.CurrentVersion.StartsWith(”7″);
}
}
For the rest keep the good blogposts coming!
@Richard I did add some caching