SDK: How to create an application deployment type with a dependency on another application’s deployment type

Update: I was incorrect in my original statements around dependency and supersedence having equivalent code. I’ll post a future example covering supersedence.

This post expands on the original sample program to demonstrate how you would add a dependency or supersedence relationship with another application. The sample here has a notable difference from the “real world” in that you would typically load the application definition for a relationship from the provider to get the required data. The sample here just clones the existing application which should be enough to demonstrate the basic concepts here.

First use the sample in this post, then add this code after line 41:

// App to act as a dependency. For this demo, just clone the existing application so we have some metadata to use. 
// If this were a real world scenario you would create an app object from an existing one loaded from the provider.
Application dependentApp = (Application)application.Clone();
// DeploymentType to act as a dependency. As with the app, we're just cloning the existing one to have some metadata. If
// this were a real world scenario, you would use a DT that is in the app instance you loaded from the provider.
DeploymentType dependentDT = (DeploymentType)scriptDT.Clone();
dependentDT.Title = "Dependency";
// Create a collection for the operands for the expression
CustomCollection<DeploymentTypeIntentExpression> operands = new CustomCollection<DeploymentTypeIntentExpression>();
operands.Add(new DeploymentTypeIntentExpression(dependentApp.Scope, dependentApp.Name, dependentApp.Version.Value, dependentDT.Scope, dependentDT.Name, dependentDT.Version.Value, DeploymentTypeDesiredState.Required, true));
// Like with any requirement rule, you can chain multiple dependencies with "And" or "Or". In this sample there's only a single dependency so it doesn't really matter.
DeploymentTypeExpression expression = new DeploymentTypeExpression(ExpressionOperator.Or, operands);
DeploymentTypeRule dependencyRule = new DeploymentTypeRule("Dependency_" + Guid.NewGuid().ToString("B"), NoncomplianceSeverity.Critical, null, expression);
// We add this other DT as a dependency. Supersedence works the same way, except you use DeploymentType.Supersedes.Add() instead.

When you execute the program, the application will contain the dependency details:

  <DeploymentTypeRule id="Dependency_{d95233f2-84ff-48c3-9761-ffc588a565fd}" Severity="Critical" xmlns="">
        <DeploymentTypeIntentExpression DesiredState="Required">
          <DeploymentTypeApplicationReference AuthoringScopeId="MyVendorId" LogicalName="Application_02ea9552-b1a6-43c9-82cf-97cfa5b0218b" Version="1" />
          <DeploymentTypeReference AuthoringScopeId="MyVendorId" LogicalName="DeploymentType_18ac74a8-781f-4bfd-940c-74e793b58a9d" Version="1" Changeable="true" />

Supersedence follows the exact same concepts except instead of adding to the Dependencies collection, you’re adding your rule to the Supersedence collection.

Download sample program Program.cs

Comments (1)

  1. Hello Adam Meltzer,

    The above example works fine but it is not adding any "Dependency Group name"

    Can you please let me know where i have to add the Dependency group Name ?

    thank you

Skip to main content