SDK: How to create a basic application and add a deployment type


Update #1: For information on enhanced detection methods, see this post.

Update #2: To avoid an exception being thrown in the administrator console, add the following code after line 12: application.DisplayInfo.DefaultLanguage = displayInfo.Language; (this has been fixed in ConfigMgr 2012 SP1)

Update #3: I have updated the sample as an attachment to this blog post so it can be more easily consumed.

Update #4: For information on requirement rules, see this post.

Update #5: For information on supersedence and dependencies, see this post.

I have seen quite a few questions being asked on how to create an application using the Configuratoin Manager 2012 SDK. Unfortunately the documentation has not yet been updated with this information so I am writing this post to provide some basic information to help you get started. This sample should compile and get you started but is by no means 100% functional.

What you will need:

  • Microsoft.ConfigurationManagement.ApplicationManagement.dll — This assembly contains the application model object library
  • Microsoft.ConfigurationManagement.ApplicationManagement.MsiInstaller.dll — This assembly contains the objects for a MSI or Script-based deployment type

These assemblies are part of the Administrator Console.

Here’s the code sample. It will create an application with a script-based deployment type, add content, and serialize to XML suitable for writing to the SMS Provider. This sample is only the application-specific portion and does not cover writing to the SMS Provider or how to deploy the application. I can provide this information in a follow-up post if there’s interest.

The first thing you’ll need to do is create an application object and add at least one AppDisplayInfo

Code Snippet
  1. // A default scope must be defined to provide a logical identifier for yourself. This is a static property and only needs to be set once.
  2. NamedObject.DefaultScope = “MyVendorId”;
  3.  
  4. Application application = new Application();
  5.             
  6. // Must define the unlocalized title for the application
  7. application.Title = “My Application”;
  8.             
  9. // At least one AppDisplayInfo is required. This contains localized application details for showing up in in Software Center or the Application Catalog
  10. AppDisplayInfo displayInfo = new AppDisplayInfo();
  11. displayInfo.Language = “en-US”;
  12. displayInfo.Title = “My Application (EN)”;
  13.  
  14. // Add the AppDisplayInfo to the Application
  15. application.DisplayInfo.Add(displayInfo);

This is enough to create a working application (you can call application.Validate() to confirm), but by itself it isn’t terribly useful since there’s no deployment types. The next thing you’ll need to do is add a deployment type, installer, and content:

Code Snippet
  1. // Create content definitions for the installer, this would point to the files that are deployed as part of the application’s package
  2. Content content = ContentImporter.CreateContentFromFolder(@”.”);
  3.             
  4. // Various options for the content on the client machine
  5. content.OnFastNetwork = ContentHandlingMode.Download;
  6. content.OnSlowNetwork = ContentHandlingMode.Download;
  7. content.FallbackToUnprotectedDP = false;
  8.             
  9. // Create an installer which will be used on the client to actually install the application
  10. ScriptInstaller installer = new ScriptInstaller();
  11.  
  12. // Add the content to the Installer
  13. installer.Contents.Add(content);
  14.  
  15. // The install command line is what’s run on the client
  16. installer.InstallCommandLine = “MyInstaller.exe x y z”;
  17.  
  18. // Use product code detection to verify if the application was installed
  19. installer.DetectionMethod = DetectionMethod.ProductCode;
  20. installer.ProductCode = “{12345678-1234-5678-9012-345678901234}”;
  21.  
  22. // Now create the deployment type and bind it to the installer
  23. DeploymentType scriptDT = new DeploymentType(installer, ScriptInstaller.TechnologyId, NativeHostingTechnology.TechnologyId);
  24. scriptDT.Title = “My Application Installer”;
  25.             
  26. application.DeploymentTypes.Add(scriptDT);
  27.  
  28. // This app definition is what’s written to the SMS Provider on the site server
  29. string appDefinition = SccmSerializer.SerializeToString(application);

After this is done, the serialized XML is appropriate for writing to an SMS_Application instance in the SMS Provider (the XML goes into the SDMPackageXML property). SMS_Application contains many lazy properties so you’ll want to re-Get the instance after creating it so the data is populated. This data will be needed to deploy the application to distribution points.

While not a complete end to end example, I hope this is a good starting point for anybody trying to create an application using the application model.

Program.cs

Comments (4)

  1. Rick Gates says:

    When trying to create an application with 1700+ sub-directories specified for source, the code hangs at installer.Contents.Add(content).  Is there a way to have the content importer not try to validate the source and just take it as is a trust me option?

  2. Rick Gates says:

    I'm looking for an example on how to mass change our applications to add OS requirement for Windows 8.1.  Since we have updated all of our clients from Windows 8 to 8.1 and SCCM 2012 R2, now we have to touch each application of which there are 750+.  I need a way to quickly add OS requirement 8.1 without having to do this one at a time in the SCCM Console.  Please send any examples to

    rick.e.gates@medtronic.com

    Thanks

  3. MKoldewijn says:

    Thanks for this useful piece of information! I have one question though, how does the part of NamedObject.DefaultScope = "MyVendorId"; translate to Powershell?

    I am using a powershell script to import applications and I want to be able to create Appv5 deployment types. When using Microsoft.ConfigurationManagement.ApplicationManagement.AppV5xContentImporter and using the method CreateDeploymentType an error is raised: Exception calling "CreateDeploymentType" with "1" argument(s): "Property NamedObject.DefaultScope must be valid prior to creating or copying any named objects."

    Any tips are appreciated!

  4. Ludovic says:

    Hello.
    Good script but I have a question.
    Do you know how to add a Logon requirement (“Only when a user is logged on” or “Wheter or not a user is logged on” or “Only when no user is logged on” to the Deployment Type?

    I script in Powershell but I don’t find the class or the parameter.

    Thank you =)

Skip to main content