次の方法で共有


How to Export a Management Pack

Applies To: System Center 2012 - Service Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

To prepare a management pack for installation, you can export it to an XML definition file, or you can package it in a management pack bundle. A management pack XML definition file does not include any resources that the management pack will need. The resources must be manually imported alongside the XML file. A management pack bundle combines the management pack and all of its resources into a single file for distribution and installation.

When a management pack references resource files, such as images or assemblies, it assigns a unique identifier to each of these resource files. For more information about creating resource references in a management pack and installing a management pack with resources, see How to Reference Resources in a Management Pack and How to Install a Management Pack with Resources.

To create a single XML definition file

  1. Get the management pack instance you want to export.

  2. Create an instance of the ManagementPackXmlWriter class supplying the directory in which the XML file will be created.

  3. Call the WriteManagementPack method supplying the management pack instance to export.

    Note

    You can use this WriteManagementPack to write out all the resource files referenced by the management pack to the same destination directory as the XML file.

When the new XML file is generated it is given the same name as the input management pack file. As an alternative option, you can write to a System.Xml.XmlWriter object by using the ManagementPackXmlWriter constructor.

To create a management pack bundle

  1. Get the management pack instance you want to export.

  2. Get an instance of the ManagementPackBundleWriter class by calling the CreateBundleWriter method with the directory in which the bundle will be created.

  3. Get an instance of the ManagementPackBundle class by calling the CreateBundle method.

  4. Call the AddManagementPack method on the bundle, passing in the management pack you want to add to the bundle.

  5. Call the Write method passing in the bundle and the name of the bundle file to write. The string representing the bundle file should not have a file name extension.

The bundle is created with a .mpb file name extension. This bundle is like a .CAB file that contains all the management packs in a single file.

To export the management pack as a bundle with resources

  1. Get the management pack instance you want to export.

  2. Get an instance of the ManagementPackBundleWriter class by calling the CreateBundleWriter method with the directory in which the bundle will be created.

  3. Get an instance of the ManagementPackBundle class by calling the CreateBundle method.

  4. Call the AddManagementPack method on the bundle, passing in the management pack you want to add to the bundle. Do this for each management pack you want to add to the bundle.

  5. Call the AddResourceStream. This method takes four parameters: the management pack that references the resource, the identifier of the resource, the ResourceStream instance, and the stream signature. Use Empty for the stream signature if you do not have one. Do this for each resource referenced by all management packs in the bundle.

  6. Call the Write method passing in the bundle and the name of the bundle file to write. The string that represents the bundle file should not have a file name extension.

The bundle is created with a .mpb file name extension. This bundle is like a .CAB file that contains all the management packs and associated resource files in a single file.

Example

The following example exports a management pack to XML.

string destinationDirectory = @".\";

ManagementPackXmlWriter mpWriter = new ManagementPackXmlWriter(destinationDirectory);
mpWriter.WriteManagementPack(mp);

The following example exports a management pack in a bundle.

string destinationDirectory = @".\";
string bundleFileName = "RePackaging.Library";

ManagementPackBundleWriter bundleWriter = ManagementPackBundleFactory.CreateBundleWriter(destinationDirectory);
ManagementPackBundle bundle = ManagementPackBundleFactory.CreateBundle();

bundle.AddManagementPack(mp);
bundleWriter.Write(bundle, bundleFileName);

The following example loads a management pack and creates a bundle. It also loads image resources used by the management pack. The management pack and image resources are then added to the bundle which is then exported as a complete management pack bundle file.

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = new ManagementPack("Folder\\RePackaging.Library.xml");

System.IO.FileStream fileStream1 = new System.IO.FileStream("Folder\\Resources\\package_16.png", System.IO.FileMode.Open);
System.IO.FileStream fileStream2 = new System.IO.FileStream("Folder\\Resources\\package_32.png", System.IO.FileMode.Open);
System.IO.FileStream fileStream3 = new System.IO.FileStream("Folder\\Resources\\package_64.png", System.IO.FileMode.Open);

ResourceStream resStream1 = new ResourceStream(mg, fileStream1);
ResourceStream resStream2 = new ResourceStream(mg, fileStream2);
ResourceStream resStream3 = new ResourceStream(mg, fileStream3);

ManagementPackBundleWriter bundleWriter = ManagementPackBundleFactory.CreateBundleWriter(".\\");
ManagementPackBundle bundle = ManagementPackBundleFactory.CreateBundle();

bundle.AddManagementPack(mp);

bundle.AddResourceStream(mp, "RePackaging.Library.Resources.Images.Package_16", resStream1, ManagementPackBundleStreamSignature.Empty);
bundle.AddResourceStream(mp, "RePackaging.Library.Resources.Images.Package_32", resStream2, ManagementPackBundleStreamSignature.Empty);
bundle.AddResourceStream(mp, "RePackaging.Library.Resources.Images.Package_64", resStream3, ManagementPackBundleStreamSignature.Empty);

bundleWriter.Write(bundle, "RePackaging.Library");

Compiling the Code

Namespaces

Microsoft.EnterpriseManagement.Configuration

Microsoft.EnterpriseManagement.Configuration.IO

Microsoft.EnterpriseManagement.Packaging

Microsoft.EnterpriseManagement

Microsoft.EnterpriseManagement.Common

Assemblies

Microsoft.EnterpriseManagement.Core

Microsoft.EnterpriseManagement.Packaging

See Also

Tasks

How to Create a Basic Management Pack
How to Reference Resources in a Management Pack
How to Install a Management Pack with Resources

Reference

ManagementPackXmlWriter
ManagementPackBundleWriter
ManagementPackBundle
ResourceStream

Other Resources

Scenario: Building a Management Pack