Skip to content

Don’t Repeat Your Biml – Include Files

Biml (Business Intelligence Markup Language) - Include Files

Are you using Biml so you won’t have to do the same tasks over and over and over again in multiple SSIS packages? If so, you probably don’t want to write the same Biml code over and over and over again either. Instead, you can move common code to separate files, centralize and reuse these files in many projects, and update code in one file to make changes to all projects. One of the ways to apply this Don’t Repeat Yourself software engineering principle in Biml is to use Include Files.

In addition to using Include Files, there are four other main ways you can avoid repeating your Biml code:

In this post we will look at how to use Include Files.

Include Files

You can think of Include Files like an automated copy and replace. The main Biml file copies all the code from the included file and pastes it into the main file. Below is a very simple example:

Package.biml:

<Packages>
  <Package Name="Package">
    <Variables>
      <#@ include file="Variables.biml" #>
    </Variables>
  </Package>
</Packages>

Variables.biml:

<Variable Name="NewRows" DataType="Int32">0</Variable>
<Variable Name="UpdatedRows" DataType="Int32">0</Variable>
<Variable Name="UnchangedRows" DataType="Int32">0</Variable>

You use the include directive <#@ include file=”…” #> to specify which file to include. When your Biml code is compiled, all code is copied from the included file and pasted instead of the include directive. It is therefore important that the included file only contains code that can replace the include directive without causing invalid syntax errors. In the example above, the include directive is used inside <Variables></Variables>, so the included file must only contain <Variable> elements.

You can include many file types, such as: .biml .txt .sql .cs and so on.

If the included file is located outside your project, you will have to use an appropriate file path. You can use both relative file paths and absolute file paths:

<!-- Relative File Path -->
<#@ include file="..\SharedCode\Variables.biml" #>

<!-- Absolute File Path -->
<#@ include file="C:\Biml\SharedCode\Variables.biml" #>

How do Include Files work?

1. The main file has an include directive. In this example, it has a red include directive:

Include Files in Biml - Main File

2. All code from the included file is copied to the main file:

Include Files in Biml - Include File

3. The include directive in the main file is replaced with the code from the included file:

Include Files in Biml - Replace Include Directive with Code

Summary

Include Files work as an automated copy and replace. You can include many file types, such as .biml .txt .sql and .cs. The include directive <#@ include file=”CommonCode.biml” #> will be replaced by the contents of the included file.

If you need more advanced features like passing parameters and controlling logic before returning code, you can use CallBimlScript instead.

Who is Cathrine Wilhelmsen?

Cathrine is a Microsoft Data Platform MVP, BimlHero, Microsoft Certified Solutions Expert, author, speaker, blogger and chronic volunteer who loves teaching and sharing knowledge. She works as a consultant, architect and developer, focusing on Data Warehouse and Business Intelligence projects. She loves sci-fi, chocolate, coffee, craft beers, ciders, cat gifs and smilies :)

Comments

Hi! This is Cathrine. Thank you so much for visiting my blog. I'd love to hear your thoughts, but please keep in mind that I'm not technical support for any products mentioned in this post :) Off-topic questions, comments and discussions may be moderated. Thanks!

Click to Show / Hide Comments