I'm using VS2008 DBPro. In my PostDeploy file I have many lines like this one
:r .\Data\Test\Classifiers.CodeType.data.sql
:r .\Data\Test\Classifiers.Currency.data.sql
:r .\Data\Test\Classifiers.LOB.data.sql
What I would like is to create a variable ProjectName so I could easely deploy different project data. Something like this (doesn't work)
:setvar ProjectName "Test"
:r .\Data\$(ProjectName)\Classifiers.CodeType.data.sql
:r .\Data\$(ProjectName)\Classifiers.Currency.data.sql
:r .\Data\$(ProjectName)\Classifiers.LOB.data.sql
It would be even better If I could read ALL files in the folder without specifying a path to it.
I have found out how this could be done.
First you need to enable xp_cmdshell utility
Next you have to define a stored procedure which will do all the work. It works by reading all files into a temporary table and then runs SQLCMD command to parse each of found *.sql files
All you have to do now is call this stored procedure (You need to pass full path to folder containing SQL files. You can get path to your project from MSBuild properties). Also note that I've added few lines around the call to RunScriptsInFolder call. Because you won't know in which order files in your folder are executed you should disable all foreign keys checks before doing it and enable them once you finished
You may also wonder why $(ProjectDir) variable doesn't work for you. To enable it open your *.dbproj file with text editor and add this code at the end.
Alternatively you can open your DB project properties, find tab Variables and add set variable ProjectDir=$(ProjectDir)