Don’t Repeat Your Biml – Include Files

Biml (Business Intelligence Markup Language) - Include FilesAre 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:

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:

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 :)

8 thoughts on “Don’t Repeat Your Biml – Include Files”

Pingback: AllDefinedSuccessors In Biml – Curated SQL

How can we update the existing package for logging without creating new package?
ex: I have developed package without event logging, I just want to create events for existing package without disturbing existing development.

Hi Hareesh, this is not possible using the free BimlExpress tool. If you invest in the licensed BimlStudio tool, you can create Transformers, which allow you to insert or change existing code without regenerating the entire package.

Is it posible to include a file in a different dir? somthing like ../environment.biml

Hi David, great question! Yes, you can use relative file paths like ..\SharedCode\Variables.biml or absolute file paths like C:\Biml\SharedCode\Variables.biml. I’ll add this to the main blog post as well :)

Thanks, but is it possible to include use a reference created earlier by c#?
like <#@ include file="Include_config.biml” #>

I mean something like this
<#@ include file="Include_ProjectConfiguration.biml” #>

Hello Catherine, I was also looking at the possibilities of file paths in things like includefile. My issue is that the shared code is located in a different project within the solution, so I would like to use hintpaths. The Biml compiler however only seems to be able to process relative paths to either the working directory, the calling project or the appdata directory. Have you found a way of using hintpaths? Otherwise its off to System.IO I guess..

Share Your Thoughts?

This site uses Akismet to reduce spam. Learn how your comment data is processed.