Reputation: 3798
I have a BIML variable of string type as below
<Variable Name="data" Datatype="String" Length="100">hello-world-2018</Variable>
I want to assign above BIML variable to C# variable or BIML Script variable in BIML file.
How to get BIML variable value and assign to C# variable ?
Upvotes: 1
Views: 1360
Reputation: 3798
I have made use of tier to compile BIML files in required order.
The BIML with lower tier value gets compiled first. For each tier objects are added to the RootNode. Higher tiers can use the Objects/Variables from the lower tier.
FirstFile : declarebimlvariable.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>
With usage of tiers and below line worked for me to access BIML variable into C# variable.
var data = RootNode.Packages.First(x => x.Name == "Practice").Variables.First(x => x.Name == "data").Value;
Upvotes: 1
Reputation: 61211
You would use something like
<Variable Name="data" Datatype="String" Length="100"><#= myBimlVariable #> </Variable>
The <#=
syntax is is a shorthand in Biml to write the current value of the variable into the xml being built
Upvotes: 1