Partilhar via


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();
 dependentApp.DeploymentTypes.Add(dependentDT);
 dependentDT.Title = "Dependency";
 dependentApp.Validate();
  
 // 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.
 scriptDT.Dependencies.Add(dependencyRule);

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

 <Dependencies>
   <DeploymentTypeRule id="Dependency_{d95233f2-84ff-48c3-9761-ffc588a565fd}" Severity="Critical" xmlns="https://schemas.microsoft.com/SystemsCenterConfigurationManager/2009/06/14/Rules">
     <DeploymentTypeExpression>
       <Operator>Or</Operator>
       <Operands>
         <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" />
         </DeploymentTypeIntentExpression>
       </Operands>
     </DeploymentTypeExpression>
   </DeploymentTypeRule>
 </Dependencies>

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

  • Anonymous
    February 25, 2013
    The comment has been removed
  • Anonymous
    May 04, 2013
    Hi Adam,Is there a method available to add Supersedence to the deployment type(s). I see that the text related to Supersedance is striken in this post.ThanksVinod
  • Anonymous
    September 15, 2013
    Hello Adam Meltzer,This example works well except it wont add the  "Dependency Group Name" so when ever we go and check in the sccm 2012 console we will get an error that the Dependency group is required.Can you please tell me how to add the dependency group. Do we have add that in the expression?I really appreciate if can help me on this.
  • Anonymous
    September 15, 2013
    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
  • Anonymous
    July 23, 2014
    I'm wondering when/if you plan to publish anything on supersedence?
  • Anonymous
    March 18, 2015
    "Dependency Group name" is set by setting the Name property on the DeploymentRuleType:dependencyRule.Name = "My dependency group";
  • Anonymous
    May 06, 2015
    Set dependentDT.Version.Value to 0 If not, if the dependancy changing, the new revision is not dependent of application and your deployment will be broken