BIML engine problem with include

Topics: Standing Discussions
Sep 13, 2012 at 10:08 AM

SQL 2012, Bidshelper 1.6.1

Include is a great feature it allows me to reuse code.. e.g. I have a connections file with all my connections.

This file is included in several other biml files. Like:
<#@ include file="Connections.biml" #>

When I generate ssis package from one file it works great. However if I want to generate more then one package from several files I get errors:
The name <> is repeated within scope.

It looks like the connections file is added more then once before generating the packages.


Sep 13, 2012 at 10:21 PM

<#@ include #> works just like copy/paste.  Think of it as copying/pasting the contents of the referenced file into the parent file.  Consequently, when you do a multi-file compile with the same includes in multiple files, you can end up with redundant definitions.  There are 2 ways to handle this:

1) If you expect most of your compilations to be multi-file, put the connections in their own first class file that you multi-select rather than including it.

2) If you want to support either multiple or single file compilations, you can add a bit of extra code to your included file to prevent it from being included more than once.  While there are several patterns to do this, this one is my favorite.  Make your Connections.biml file look like this:


<# if (!ValidationReporter.ValidationItems.Any(item => item.Message == "ConnectionsIncluded")) {

	ValidationReporter.Report(Severity.Message, "ConnectionsIncluded"); #>


		<Connection Name="Connection1" ConnectionString="key=value" />


<# } #>


When emitting connections, we also add a message to the validation reporter that this is happening.  Then we only add the connections code if that message isn't already present.  This guarantees that the code can only be included once.  I like this approach because it has the side effect of also adding the inclusion to any logging that we collect from the compiler.

Please let us know if that doesn't solve it for you. 

Sep 14, 2012 at 3:26 PM

The if statement solved my problem.

Thanx! Scott