Skip to content

Instantly share code, notes, and snippets.

@NReilingh
Last active July 14, 2016 00:15
Show Gist options
  • Save NReilingh/73291393cbe8596402d3618858848f06 to your computer and use it in GitHub Desktop.
Save NReilingh/73291393cbe8596402d3618858848f06 to your computer and use it in GitHub Desktop.
Documentation for BuildHelper.exe, a simple tool for concatenating files, specifically written for SQL Server projects.

Sebastian Meine (@sqlity) created BuildHelper.exe as a component of a build process for T-SQL scripts in a SQL Server Management Studio (SSMS) project. This tool is made available as part of the build system for the tSQLt project, and can be downloaded here:

https://github.com/tSQLt-org/tSQLt/blob/master/Build/BuildHelper.exe

Example Use Case

An example build and deploy process would involve kicking off a batch file from SSMS, which would trigger BuildHelper.exe with a designated set of arguments. BuildHelper would output a single .sql file from all of your scripts, which could then be run by your batch file using an invocation of sqlcmd.

Usage

Invoking BuildHelper.exe from the command line will display a short usage summary:

Usage: BuildHelper "sqlFileListFileName" "outputFileName" ["bracketSymbol" ["+"]]
       If last parameter ("+") is supplied, the first lines of each file are included.

Input

sqlFileListFileName and outputFileName, the two required arguments, are both paths specified relative to your working directory.

The sqlFileList file is a plain text file containing a list (newline delimited) of paths, relative to the sqlFileList file, to plain text files that will be concatenated in the order specified and written to output.

Output

The content of each included file will be followed by no less than three newlines, the word GO (the default SSMS batch separator keyword), and two more newlines. The GO keyword ensures that code from two different files will not be executed in the same batch accidentally. Additionally, the output file will end with an additional newline.

Build "Flags"

If the bracketSymbol argument is included, content from each file in the sqlFileList will only be included in the output if it is between a start bracket and end bracket. These brackets are lines containing your bracketSymbol appended with a + and - respectively. Multiple bracketed blocks per file are allowed. Thus, if your bracketSymbol argument is --build, your start bracket would be --build+ and your end bracket would be --build-.

If, additionally, the + argument is included after the bracketSymbol argument, then content from the top of each file will be included in the output up until the first start bracket in the file, and bracket behavior will continue as normal from there. If there are no symbols in the file, the entire file will be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment