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
- // 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.
- NamedObject.DefaultScope = "MyVendorId";
- Application application = new Application();
- // Must define the unlocalized title for the application
- application.Title = "My Application";
- // At least one AppDisplayInfo is required. This contains localized application details for showing up in in Software Center or the Application Catalog
- AppDisplayInfo displayInfo = new AppDisplayInfo();
- displayInfo.Language = "en-US";
- displayInfo.Title = "My Application (EN)";
- // Add the AppDisplayInfo to the Application
- 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:
- // Create content definitions for the installer, this would point to the files that are deployed as part of the application's package
- Content content = ContentImporter.CreateContentFromFolder(@".");
- // Various options for the content on the client machine
- content.OnFastNetwork = ContentHandlingMode.Download;
- content.OnSlowNetwork = ContentHandlingMode.Download;
- content.FallbackToUnprotectedDP = false;
- // Create an installer which will be used on the client to actually install the application
- ScriptInstaller installer = new ScriptInstaller();
- // Add the content to the Installer
- installer.Contents.Add(content);
- // The install command line is what's run on the client
- installer.InstallCommandLine = "MyInstaller.exe x y z";
- // Use product code detection to verify if the application was installed
- installer.DetectionMethod = DetectionMethod.ProductCode;
- installer.ProductCode = "{12345678-1234-5678-9012-345678901234}";
- // Now create the deployment type and bind it to the installer
- DeploymentType scriptDT = new DeploymentType(installer, ScriptInstaller.TechnologyId, NativeHostingTechnology.TechnologyId);
- scriptDT.Title = "My Application Installer";
- application.DeploymentTypes.Add(scriptDT);
- // This app definition is what's written to the SMS Provider on the site server
- 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.
Can you provide an example of taking the serialized string in appdefinition variable and creating the sccm application object using the SMS Provider?
Adam,
Can you post the necessary script code to actually get the serialized .XML into the SCCM database thru the SMS provider? Your script is the best & MOST COMPLETE method I've seen so far for automating the application creation process outside of creating everything manually. This is especially helpful since the cmdlet's leave a lot to be desired in their current state.
Secondly, any idea how to convert the script to VB or .NET?
I need help on how to set the Application Owner
How can I get the ApplicationManagement.User object (I have a string as input and have to create the user object for it)
Any Example code in C##
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?
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
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!
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 =)