Creating App-V DeploymentType with API

For anyone who's working with the API, I'd like to pass along this very excellent tidbit that I stumbled over and found extremely useful.  Mucho gracias to those who created it.

code.msdn.microsoft.com/Sample-SCCM-Application-376c9124/view/Discussions

I'm having a hard time getting the method to create App-V deployment types working, though.  I've been through all the documentation but there's something I'm not setting up right.  Would someone be kind enough to have a peek at what I'm doing and correct me or post a code example of their own?

public static DeploymentType CreateAppvDeploymentType(string title, string manifestFile, string contentFolder)
        {
            AppvInstaller installer = new AppvInstaller();

            installer.ManifestFile = manifestFile;
            installer.RequireLoad = false;

            // Only add content if specified and exists.
            if (Directory.Exists(contentFolder) == true)
            {
                Content content = ContentImporter.CreateContentFromFolder(contentFolder);
                
                if (content != null)
                {
                    content.OnFastNetwork = ContentHandlingMode.DownloadContentForStreaming;
                    content.OnSlowNetwork = ContentHandlingMode.DoNothing;
                    content.FallbackToUnprotectedDP = true;
                    content.PinOnClient = false;
                    content.Location = contentFolder;

                    ContentFile file = new ContentFile();
                    file.Name = manifestFile;
                    content.Files.Add(file);
                    installer.Contents.Add(content);
                }
            }

            DeploymentType dt = new DeploymentType(installer, AppvInstaller.TechnologyId, NativeHostingTechnology.TechnologyId);
            dt.Title = title;

            return dt;
            }

June 25th, 2013 1:41pm

beuller...?  Beuller...?  Beuller......?  :)
Free Windows Admin Tool Kit Click here and download it now
July 1st, 2013 10:56pm

Answering my own question again.  Finally had time sit down and mess with this for a while.  For anyone who needs it, here is creating AppV4 and AppV5 deployment types using API.

        private int CreateAppv4DeploymentType(WqlConnectionManager connection, string appManifest, string parentApplicationName, string dtName)
        {
            try
            {
                SetStatusStrip("Creating AppV4 Deployment Type");
                SetNamedScopeForSCCMRequest(connection);
                AppvContentImporter importer = new AppvContentImporter();
                DeploymentType dt = importer.CreateDeploymentType(appManifest);
                dt.Title = dtName;
                dt.Installer.Contents[0].FallbackToUnprotectedDP = true;
                dt.Installer.Contents[0].OnFastNetwork = ContentHandlingMode.DownloadContentForStreaming;
                dt.Installer.Contents[0].OnSlowNetwork = ContentHandlingMode.DoNothing;
                dt.Installer.Contents[0].PinOnClient = false;
                dt.Installer.Contents[0].PeerCache = true;
                //retrieve the application here to then add the deployment type
                sccm.Application application = GetApplicationFromName(connection, parentApplicationName);
                application.DeploymentTypes.Add(dt);
                //resave the application
                SaveApplication(connection, application);
                return 0;
            }
            catch (SmsException e)
            {
                MessageBox.Show("Problem creating Deployment Type. Error: " + e.Message, "Notice");
                return 1;
            }
        }

private int CreateAppv5DeploymentType(WqlConnectionManager connection, string appManifest, string parentApplicationName, string dtName) { try { SetStatusStrip("Creating AppV5 Deployment Type"); SetNamedScopeForSCCMRequest(connection); AppV5xContentImporter importer = new AppV5xContentImporter(); DeploymentType dt = importer.CreateDeploymentType(appManifest); dt.Title = dtName; dt.Installer.Contents[0].FallbackToUnprotectedDP = true; dt.Installer.Contents[0].OnFastNetwork = ContentHandlingMode.DownloadContentForStreaming; dt.Installer.Contents[0].OnSlowNetwork = ContentHandlingMode.DoNothing; dt.Installer.Contents[0].PinOnClient = false; dt.Installer.Contents[0].PeerCache = true; //retrieve the application here to then add the deployment type sccm.Application application = GetApplicationFromName(connection, parentApplicationName); application.DeploymentTypes.Add(dt); //resave the application SaveApplication(connection, application);

return 0; } catch (SmsException e) { MessageBox.Show("Problem creating Deployment Type. Error: " + e.Message, "Notice"); return 1; } }




August 30th, 2013 3:13pm

What is the API used in this example?
where AppV5xContentImporter is found

Thanks

Free Windows Admin Tool Kit Click here and download it now
September 18th, 2013 6:03pm

Thank you, this saved me hours - possibly days :) Just noticed one dilemma; the importer doesn't seem to include "Requirements", if a package is limited to certain platforms when sequenced it's not reflected in the created DT. It's fairly simple to add a requirement, my problem is, I don't know what they are - must be read from the appv-file, but how?
October 19th, 2013 6:56pm

I can't seem to get past this part

AppV5xContentImporter importer = new AppV5xContentImporter();
DeploymentType dt = importer.CreateDeploymentType(appManifest);

When creating Deployment on the secon line I get the unhandled Exception "Invalid deployment technology id: AppV5X"
I've added a reference to Microsoft.ConfigurationManagement.ApplicationManagement.AppV5XInstaller

Is there something else I'm missing. Having no problems with App-V 4 or other technologies.

Free Windows Admin Tool Kit Click here and download it now
October 21st, 2013 9:05pm

Provided that appManifest holds the full path to your "*.appv" you also have to add "Microsoft.ConfigurationManagement.ZipArchive.dll"
October 21st, 2013 9:52pm

Provided that appManifest holds the full path to your "*.appv" you also have to add "Microsoft.ConfigurationManagement.ZipArchive.dll"

Thanks for your input. Still the same result. I feel that the archive -appv hasn't even been touched at this point. My understanding is that the DeploymentType class DeploymentTechnology does not support "APPV5X". Just the original technologys. "MSI", "APPV" etc.

AppV5xDeploymentTechnology

has the member public const stringTechnologyId = "AppV5X"; Which evidently is being used by

AppV5xContentImporter

However this is not a valid property in DeploymentType How do I override that or add this Technology... Are my reference DLL\s old??
They are from november 2012. For instance

Microsoft.ConfigurationManagement.ApplicationManagement;

Free Windows Admin Tool Kit Click here and download it now
October 21st, 2013 10:47pm

Provided that appManifest holds the full path to your "*.appv" you also have to add "Microsoft.ConfigurationManagement.ZipArchive.dll"

Thanks for your input. Still the same result. I feel that the archive -appv hasn't even been touched at this point. My understanding is that the DeploymentType class DeploymentTechnology does not support "APPV5X". Just the original technologys. "MSI", "APPV" etc.

AppV5xDeploymentTechnology

has the member public const stringTechnologyId = "AppV5X"; Which evidently is being used by

AppV5xContentImporter

However this is not a valid property in DeploymentType How do I override that or add this Technology... Are my reference DLL\s old??
They are from november 2012. For instance

Microsoft.ConfigurationManagement.ApplicationManagement;

October 22nd, 2013 1:58pm

What is the API used in this example?
where AppV5xContentImporter is found

Thanks

You will find it by adding a reference to

Microsoft.ConfigurationManagement.ApplicationManagement.AppV5xInstaller.dll

Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2013 2:00pm

Per Elmster

Problem Solved

Updated Microsoft.ConfigurationManagement.ApplicationManagement to the version in SCCM 2012 SP1

My DLL was actually from february 2012, not novemeber as it should have been.

October 22nd, 2013 4:47pm

I get my requiorements set allright. However I set them myself in a wizard before I create the Application. Then add them to the deployment same way as any other DepoymentType technplogy.

I haven't tried reading the requirements out of the manifest yet. What I'm doing right now is tryong to read the field Processor Architecture out of the manifest. I know it's there because I found it by opening with notepad :-)

Working with extracting info out of the manifest right now with ZipArchive class and this is as far as I've gotten.

        private void DisplayText(string fileName)
        {
            System.IO.Compression.ZipArchive zipV = new System.IO.Compression.ZipArchive(fileName);
            
            richTextBox1.AppendText("Archive contains " + zipV.Entries.Count + " entries \r\n");
            richTextBox1.AppendText(" " + zipV.GetEntry("Root/Orca/Orca.exe") + "\r\n");
            
            for ( int i = 0; i < zipV.Entries.Count; i++ )
            {
                richTextBox1.AppendText(zipV.Entries[i].ToString() + "\r\n");
            
            }
        }

Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2013 7:36pm

Working with extracting info out of the manifest right now with ZipArchive class and this is as far as I've gotten.

        private void DisplayText(string fileName)
        {
            System.IO.Compression.ZipArchive zipV = new System.IO.Compression.ZipArchive(fileName);
            
            richTextBox1.AppendText("Archive contains " + zipV.Entries.Count + " entries \r\n");
            richTextBox1.AppendText(" " + zipV.GetEntry("Root/Orca/Orca.exe") + "\r\n");
            
            for ( int i = 0; i < zipV.Entries.Count; i++ )
            {
                richTextBox1.AppendText(zipV.Entries[i].ToString() + "\r\n");
            
            }
        }		
October 22nd, 2013 8:07pm

Thanks for pointing me forward.
Doing the same now, except I am opening the XmlTextreader from an iostream instead. That way I don't have to extract a file. However I did that just get a grip of what's in there.

Just this addition to your code.

 

            System.IO.Stream stream = zipArchiveEntry.Open();

            XmlTextReader reader = null;
            reader = new XmlTextReader(stream);

           
            while (reader.Read())........

Of course I didn't find the same things you did :-(

This element was not to be found
"appv:TargetOS"

I found this line
<TargetOSes  SequencingStationProcessorArchitecture="x64" xmlns="http://schemas.microsoft.com/appv/2010/manifest" />
However reader.Name stops reading at the first sign of whitespace and I never get my hands on ProcessorArchitecture="x64"

Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2013 10:51pm

This looks very useful. How do I translate this to Powershell however?

What I try to accomplish is to create an AppV5 deployment type within a powershell script. The CreateDeploymentType method keeps raising the error: "Property NamedObject.DefaultScope must be valid prior to creating or copying any named object.

No clue on how to overcome this. Any help would be appreciated.

May 13th, 2015 4:01am

Can't you use Add-CMDeploymentType (https://technet.microsoft.com/en-us/library/jj870953(v=sc.20).aspx)?
Free Windows Admin Tool Kit Click here and download it now
May 13th, 2015 4:15am

I could use Add-CMDeploymentType, but I would like to set requirement rules when creating the deploymenttype. This is not a feature of Add-CMDeploymentType.

May 18th, 2015 2:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics