I have some BIML that generates SSIS packages based on data in some config files.
I have C# code in the BIML to read the config files and use the data within them when building the SSIS packages.
However, I currently have to hard code the path to the config files in my C#. I would prefer to use a relative path from the BIML files. Is this possible? (Or is there a simpler way?)
Minimal example with everything in one BIML file (in reality I have separate C# files):
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#
// I would like a directory path to any of my BIML or C# files here.
var CodeBase = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
var BaseDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
var CurrentDirectory = Environment.CurrentDirectory;
var GetCurrentDirectory = System.IO.Directory.GetCurrentDirectory();
var GetFullPath = System.IO.Path.GetFullPath(".");
#>
<Packages>
<Package Name="Demo_paths" ConstraintMode="Linear">
<Variables>
<Variable Name="CodeBase" DataType="String" IncludeInDebugDump="Exclude" EvaluateAsExpression="false">
<#=CodeBase#>
</Variable>
<Variable Name="BaseDirectory" DataType="String" IncludeInDebugDump="Exclude" EvaluateAsExpression="false">
<#=BaseDirectory#>
</Variable>
<Variable Name="CurrentDirectory" DataType="String" IncludeInDebugDump="Exclude" EvaluateAsExpression="false">
<#=CurrentDirectory#>
</Variable>
<Variable Name="GetCurrentDirectory" DataType="String" IncludeInDebugDump="Exclude" EvaluateAsExpression="false">
<#=GetCurrentDirectory#>
</Variable>
<Variable Name="GetFullPath" DataType="String" IncludeInDebugDump="Exclude" EvaluateAsExpression="false">
<#=GetFullPath#>
</Variable>
</Variables>
</Package>
</Packages>
</Biml>
I've also tried RootNode.BimlFile but that doesn't work in the minimal repro, and only appears to give the file name of the file, not its path on disk.
The variables in the above have the following values
BaseDirectory:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\
CodeBase:
file:///C:/Users/<USERNAME>/AppData/Local/Temp/Varigence/230028/4pxczy3m.dll
CurrentDirectory:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE
GetCurrentDirectory:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE
GetFullPath:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE