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.
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:
<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.
How do Include Files work?
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.