Question: In our SSDT project we have a script that is huge and contains a lot of INSERT statements for importing data from an old system. Using sqlcmd variables, I'd like to be able to conditionally include the file into the post deployment script.

We're currently using the `:r` syntax which includes the script inline:

```
IF '$(ImportData)' = 'true'
BEGIN
  :r .\Import\OldSystem.sql
END

```

This is a problem because the script is being included **inline** regardless of whether `$(ImportData)` is true or false and the file is so big that it's slowing the build down by about 15 minutes.

Is there another way to conditionally include this script file so it doesn't slow down the build?

Answer: 
Rather than muddy up my prior answer with another. There is a special case with a VERY simple option.

Create separate SQLCMD input files for each execution possibility.
The key here is to name the execution input files using the value of your control variable.

So, for example, your publish script defines variable 'Config' which may have one of these values: 'Dev','QA', or 'Prod'.

Create 3 post deployment scripts named 'DevPostDeploy.sql', 'QAPostDeploy.sql' and 'ProdPostDeploy.sql'.

Code your actual post deploy file like this:

:r ."\"$(Config)PostDeploy.sql

This is very much like the build event mechanism where you overwrite scripts with appropriate ones except you don't need a build event. But you are dependent upon naming your scripts very specifically.
I ended up using a mixture of our build tool (Jenkins) and SSDT to accomplish this. This is what I did:

1. Added a build step to each environment-specific Jenkins job that writes to a text file. I either write a SQLCMD command that includes the import file or else I leave it blank depending on the build parameters the user chooses.
2. Include the new text file in the Post Deployment script via `:r`.

That's it! I also use this same approach to choose which pre and post deploy scripts to include in the project based on the application version, except that I grab the version number from the code and write it to the file using a pre-build event in VS instead of in the build tool. (I also added the text file name to `.gitignore` so it doesn't get committed)