Here's how I handle conditional deployment in the post-deployment process to deploy test data for the Debug configuration, but not Release.
First, in the Solution Explorer, open the project properties folder and right-click to add a new SqlCmd.variables file.
Name the file Debug.sqlcmdvars .
Inside the file, add your custom variables, and then add the final variable named $(BuildConfiguration) and set the value to Debug.
Repeat this process to create Release.sqlcmdvars, setting $(BuildConfiguration) for release.
Now configure your configurations: Open the project properties page on the "Expand" tab. In the top drop-down list, configure as Debug. In the bottom drop-down list (Sql command variables) set the file in Properties \ Debug.sqlcmdvars.
Repeat for release as: In the upper drop-down list, set the configuration for release. In the bottom drop-down list (Sql command variables) set the file to Properties \ Release.sqlcmdvars.
Now, in your Script.PostDeployment.sql file, you can specify conditional logic, for example:
IF 'Debug' = '$(BuildConfiguration)' BEGIN PRINT '***** Creating Test Data for Debug configuration *****'; :r .\TestData\TestData.sql END
In Solution Explorer, right-click the top-level solution and open Configuration Manager. You can specify which configuration is active for your assembly. You can also specify the configuration on the command line MSBUILD.EXE.
Now you can: now your developer builds contain test data, but not your release builds!
Rob McCauley Jan 13 '12 at 21:14 2012-01-13 21:14
source share