Skip to main content

Viewing or Saving the Compiled Biml File

Why the Intermediate Result Matters

The Biml engine compiles each Biml document, applies any embedded BimlScript in memory, then emits SSIS packages. The intermediate XML that exists between the script expansion and the package emission is not persisted to disk by default. When BimlScript logic gets complex, that intermediate XML is exactly what is needed to find the bug: which loop produced which element, which attribute came out empty, where a code nugget collapsed unexpectedly.

A second Biml file at a higher tier can capture the result by serializing the in-memory tree to disk before SSIS generation runs.

The Technique

Biml files compile in tier order: lower tiers first, higher tiers last. The default tier is 0 for files without BimlScript and 1 for files with BimlScript. By placing a small helper file at a tier higher than every other file in the project, that helper can read the fully assembled root node and write its serialized form to disk.

Add a new Biml file to the project named 'SaveCompiledBiml.biml' and place it at a tier above the highest tier already in use. The example below assumes the rest of the project tops out at tier 4, so the helper sits at tier 5:

<#@ template tier="5" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="Varigence.Languages.Biml" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#
string sFile = @"C:\BimlOutput\compiled.biml";
Directory.CreateDirectory(Path.GetDirectoryName(sFile));
File.WriteAllText(sFile, RootNode.GetBiml());
#>
</Biml>

When the project compiles, every other Biml file finishes first, so by the time the tier 5 helper runs, 'RootNode' contains the fully expanded tree. Calling 'GetBiml' on the root node returns the serialized XML, which 'File.WriteAllText' drops on disk.

Adjust the Tier to Match the Project

The helper has to run last. If the project already uses tier 5, move the helper to tier 6 or higher. The pattern is the same: pick any tier strictly greater than the highest tier any other file uses, set it in the 'template tier' directive, and the helper picks up the assembled tree.

Adjust the Output Path

Change the 'sFile' variable to any writable location. The directory does not have to exist beforehand because 'Directory.CreateDirectory' will create the parent path if it is missing.

What to Look For in the Output

Open the saved file in any XML editor. The result is plain Biml without code nuggets, with every loop unrolled, every variable substituted, and every conditional resolved. Comparing what is on disk against what was expected pinpoints the BimlScript expression that produced the wrong shape, often within a few seconds.