William Jockusch
William Jockusch

Reputation: 27295

Detect Visual studio build configuration in sql post deployment script

I have a VS solution whose purpose is to publish an sql database, via .sqlproj. It runs a post deployment script. I would like to set it up for multiple publish workflows. I want my sql post deployment script do do something like the following (pseudo-code):

if (VS build configuration is debug1)
BEGIN
  :r .\Debug1Setup.sql
END
else if (VS build configuration is debug2)
BEGIN
  :r .\Debug2Setup.sql
END

Is that possible?

Upvotes: 1

Views: 472

Answers (1)

Caius Jard
Caius Jard

Reputation: 74605

You can probably leverage the post-build command system in VS for this; in your project properties, on the build events tab you can enter commands together with variables that are expanded by VS before the command runs. $(ConfigurationName) is populated with the name of the active configuration. See https://learn.microsoft.com/en-us/visualstudio/ide/reference/pre-build-event-post-build-event-command-line-dialog-box?view=vs-2019 for more information. Pre/post build are executed like normal DOS batch files; any commands that work in DOS also work in them.

enter image description here

If the commands you want to execute cannot (or should not) be put in a post build script, you could consider having a post build script that modifies some other file, passing in the build configuration - for example you could programmatically create a batch file that contains the active configuration upon every build, but only run that batch file some times

Upvotes: 1

Related Questions