Package.ExportConfigurationFile(String) Methode

Definition

Erstellt eine XML-Datei, die alle bereitstellbaren Variablen im Paket enthält.

public:
 void ExportConfigurationFile(System::String ^ str);
public void ExportConfigurationFile (string str);
member this.ExportConfigurationFile : string -> unit
Public Sub ExportConfigurationFile (str As String)

Parameter

str
String

Der Pfad zur Konfigurationsdatei.

Beispiele

Im folgenden Beispiel wird ein neues Paket erstellt, auf truefestgelegt EnableConfigurations und die ExportConfigurationFile -Eigenschaft festgelegt. Im Beispiel wird dem Paket dann eine neue Konfiguration hinzugefügt und der Wert von ConfigurationString, ConfigurationTypeund PackagePathfestgelegt.

static void Main(string[] args)  
        {  
            // Create a package and set two properties.  
            Package pkg = new Package();  
            pkg.EnableConfigurations = true;  
            pkg.ExportConfigurationFile(@"C:\conf.xml");  

            // Create a variable object and add it to the   
            // package Variables collection.  
            Variable varPkg = pkg.Variables.Add("var", false, "", 100);  
            varPkg.Value = 1;  
            string packagePathToVariable = varPkg.GetPackagePath();  

            // Create a configuration object and add it to the   
           // package configuration collection  
            Configuration config = pkg.Configurations.Add();  

           // Set properties on the configuration object.  
            config.ConfigurationString = "conf.xml";  
            config.ConfigurationType = DTSConfigurationType.ConfigFile;  
            config.PackagePath = packagePathToVariable;  

            //save the package and its configuration  
            Application app = new Application();  
            app.SaveToXml(@"c:\pkg.xml", pkg, null);  

            //Reload the package  
            Package p1 = app.LoadPackage(@"c:\pkg.xml", null);  
            //Review its Variables collection  
            Console.WriteLine("The value of variable VAR = " + p1.Variables["var"].Value);  
        }  
Shared  Sub Main(ByVal args() As String)  
            ' Create a package and set two properties.  
            Dim pkg As Package =  New Package()   
            pkg.EnableConfigurations = True  
            pkg.ExportConfigurationFile("C:\conf.xml")  

            ' Create a variable object and add it to the   
            ' package Variables collection.  
            Dim varPkg As Variable =  pkg.Variables.Add("var",False,"",100)   
            varPkg.Value = 1  
            Dim packagePathToVariable As String =  varPkg.GetPackagePath()   

            ' Create a configuration object and add it to the   
           ' package configuration collection  
            Dim config As Configuration =  pkg.Configurations.Add()   

           ' Set properties on the configuration object.  
            config.ConfigurationString = "conf.xml"  
            config.ConfigurationType = DTSConfigurationType.ConfigFile  
            config.PackagePath = packagePathToVariable  

            'save the package and its configuration  
            Dim app As Application =  New Application()   
            app.SaveToXml("c:\pkg.xml", pkg, Nothing)  

            'Reload the package  
            Dim p1 As Package =  app.LoadPackage("c:\pkg.xml",Nothing)   
            'Review its Variables collection  
            Console.WriteLine("The value of variable VAR = " + p1.Variables("var").Value)  
End Sub  

Beispielausgabe:

The value of variable VAR = 1

Hinweise

Sie können die Konfigurationsdatei bearbeiten und die Werte für die computerabhängigen Variablen ändern. Jedes Mal, wenn das Paket auf einem anderen Computer bereitgestellt wird, verwendet es bei der Ausführung die computerabhängigen Variablen auf diesem Computer. Weitere Informationen finden Sie unter Erstellen von Paketkonfigurationen.

Gilt für: