Variable.GetPackagePath 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回变量所属的包的路径。
public:
virtual System::String ^ GetPackagePath();
public string GetPackagePath ();
abstract member GetPackagePath : unit -> string
override this.GetPackagePath : unit -> string
Public Function GetPackagePath () As String
返回
包含包路径的字符串。
实现
示例
以下示例创建一个新包、设置为EnableConfigurationstrue
该包并设置该ExportConfigurationFile属性。 然后,该示例向 Variables 集合添加新变量,设置值,并使用 检索包路径 GetPackagePath。 此外,配置将添加到包值的配置集合中 ConfigurationString, ConfigurationType以及 PackagePath。
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
示例输出:
变量 VAR = 1 的值