Derik Whittaker



Deploying Database Projects with psake

Recently I joined a project that was using a Sql Server Database Project to manage their DB scheme and so far it is pretty cool.  This project type like others has a deploy/publish option which will allow you to publish your changes to a target database.  And like other project types this is very easy to do via Visual Studio, but if you know me you will know that I like to automate tasks like these rather than have to use the IDE so I did.  Here is what I did in order to use pSake, a build automation tool written in powershell, to handle my clean, build and deployment of my database projects.

Step 1: Learn

Understand the automation options available for this project type and MSBuild

Step 2: Create your psake task file (database.upgrade.ps1)

**** Please not that the formatting of the MSBuild above will NOT RUN and is done to allow the sample code to be clean.  You the entire MSBuild task needs to be on ONE LINE ****

**** I am setting my properties to ‘parm’ variables because I am passing these into the script by using the –parameters feature of psake ****

There is one part of the MSBuild task above that you MUST PAY ATTENTION TO, that is the way items are escaped.  They are being escaped with the back tick (`).  If you omit this you are going to get some odd errors depending on what you do.  These errors could range from ‘Multiple projects were provided’ to issues with the connection string not being formatted.  The root cause for these errors and the need to use the back tick (`) has to do with white space in the connection string… ugg

One you have this psake task setup you can call it like any other task and it should just work.

Till next time,

Posted 03-19-2013 5:32 AM by Derik Whittaker
Filed under: ,



Sean Kearon wrote re: Deploying Database Projects with psake
on 03-20-2013 4:12 AM

How would you use this to deploy to multiple environments (test, live, etc.)?

Bruno wrote re: Deploying Database Projects with psake
on 03-21-2013 7:59 AM

I believe:

**** Please not that

should be:

**** Please note that ?

Couldn't find a way to contact you other than here.

Please delete this comment once you get it.

Thanks for the post!

buy social bookmarks wrote re: Deploying Database Projects with psake
on 04-04-2013 12:21 AM

m8BVw6 Say, you got a nice blog article. Fantastic.

comedy channel wrote re: Deploying Database Projects with psake
on 04-06-2013 1:14 AM

I really enjoy the blog post. Awesome.

Social bookmarks wrote re: Deploying Database Projects with psake
on 04-12-2013 2:41 PM

y7k2YN Great, thanks for sharing this blog post.Thanks Again. Want more.

social bookmarking service wrote re: Deploying Database Projects with psake
on 04-12-2013 9:03 PM

gkdxm1 I really enjoy the article post.Really thank you!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)