0

I want to be able to determine in code if the current Sitecore instance is an XP or XM. As far I can see there is no direct way to do this, am I correct? If so, would it be advised to check if xdb is enabled in order to determine if the current instance is an XP or XM?

Kind regards, Alex

1
  • See if this old code helps. May be you can get it from sitecore system info. – Debabrata Biswas Aug 25 '20 at 13:53
1

Personally, I wouldn't depend on "Sitecore.Xdb.Configuration.XdbSettings.Enabled" setting. From (I believe) Sitecore 9.1 and onwards, Sitecore delivered XM packages and XP packages. Although XP can run in XM mode, it is still an XP instance. The XM package does not contain any specific XP assemblies, such as the Sitecore.Analytics assembly. This means that the following code probably doesn't work, as the xDB assembly isn't available at all in the XM package:

Sitecore.Xdb.Configuration.XdbSettings.Enabled

To overcome this, you could explicitly check if certain "XP specific assemblies" have been loaded or not, just by executing this logic:

var isXP = ContainsAssembly("Sitecore.Analytics");

private bool ContainsAssembly(string name)
    {
        bool assemblyLoaded = false;
        var assemblies = AppDomain.CurrentDomain.GetAssemblies();
        foreach (var assembly in assemblies)
        {
            var assemblyName = assembly.GetName();
            if (assemblyName.Name == name)
            {
                assemblyLoaded = true;
                break;
            }
        }
        return assemblyLoaded;
    }

if the assembly is not in the app domain, you can be pretty sure that you are running an XM instance (and thus, XM mode). IF it is available, you can run extra checks, to see if you are running XP or XM mode in an XP instance

0

One way I can think is if you are on Azure, you can use powershell to get the list of apps in your subscription plan. Once you have the list of apps, you can check if the app's name matches with the app names for marketing automation, xconnect, cortex etc. If matches are found, the instance is necessarily XP else XM. Below sample code can help to start with it -

function IsXpInstance($subscriptionId, $resourceGroupName) {   
Write-Host "Selecting subscription $($subscriptionId)..."
Select-AzureRmSubscription -SubscriptionId $subscriptionId
Write-Host "Selecting web apps..."    
$webApps = Get-AzureRmWebApp -ResourceGroupName $resourceGroupName
#Check for webapp names to be sure. They may have got updated with newer versions of Sitecore
$webApps | % {
    if ($_.Name.EndsWith("-ma-ops") -or $_.Name.EndsWith("-ma-rep") -or $_.Name.EndsWith("-xc-collect") `
        -or $_.Name.EndsWith("-xc-search") -or $_.Name.EndsWith("-xc-refdata")) {
        Write-Host -f Green " [XP]"
        break;
    }
}

}

If you want to achieve this in CSharp, you can make use of Azure APIs to fetch the collection of webApps related to subscription and then do the same.

0

Using Code:

Sitecore.Xdb.Configuration.XdbSettings.Enabled

True = xdb Enabled = XP is enabled

False = XP is disabled = XM only mode

Using Config:

In the file Sitecore.Xdb.config find <setting name="Xdb.Enabled" value="true" />

you can also check that setting in powershell.

I don't know the reason behind your question, but I have a feeling there must be a better approach than checking if it's XP or XM.

https://doc.sitecore.com/developers/92/platform-administration-and-architecture/en/enable-disable-the-xdb-and-the-tracker.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.