如何将BIML变量分配给BIMLScript变量?

时间:2018-07-13 21:35:55

标签: ssis biml

我有一个BIML变量,其字符串类型如下

<Variable Name="data" Datatype="String" Length="100">hello-world-2018</Variable>

我想将BIML变量分配给BIML文件中的C#变量或BIML脚本变量。

如何获取BIML变量值并分配给C#变量?

2 个答案:

答案 0 :(得分:1)

我已经使用 tier 来按要求的顺序编译BIML文件。

层级值较低的BIML首先被编译。对于每个层,将对象添加到RootNode。较高的层可以使用较低层的对象/变量。

FirstFile :clarifybimlvariable.biml

<#@ template tier="0" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Packages>
        <Package Name="Practice">
            <Variables>
                <Variable Name="data" Datatype="String" Length="100">hello-world-2018</Variable>
            </Variables>
        </Package>
    </Packages>
</Biml>

SecondFile :getbimlvariableincsharp.biml

<#@ template tier="1" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Packages>
        <Package Name="Practice2">
            <#
                var data = RootNode.Packages.First(x => x.Name == "Practice").Variables.First(x => x.Name == "data").Value;
            #>
            <Tasks>
                <Dataflow Name="<#= data#>">

                </Dataflow>
            </Tasks>
        </Package>
    </Packages>
</Biml>

通过使用层和下面的行,我可以将BIML变量访问到C#变量中。

var data = RootNode.Packages.First(x => x.Name == "Practice").Variables.First(x => x.Name == "data").Value;

答案 1 :(得分:0)

您将使用类似的

<Variable Name="data" Datatype="String" Length="100"><#= myBimlVariable #> </Variable> 

<#=语法是Biml的简写形式,用于将变量的当前值写入正在构建的xml中

相关问题