When you develop web applications you usually have X developers solving bugs and implementing features, and a series of testers that test application during developing process. A must to have requirement is that
- Modifications to the trunk are visible as soon as possible to testers.
- Data in test database gets preserved
Point 2 is especially important, testers usually work with the site and fills database with data. Suppose that tester John find a bug that occurs only with specific data, a developer correct the bug, then a deploy is done, all test data are wiped away, and the tester is not able to verify if the bug is gone.
Moreover testers usually fill the database with real data useful for testing, then you need to deploy update to web application while updating database schema preserving data. The optimum solution is the one represented by this schema
When a developer does a check-in or at a scheduled time the build server gets latest bit of the tip, then compile it, and update the web server pointing IIS to the new version and updating schema of the database in the meanwhile, preserving all the data inside the test db.
It is absolutely not a complex stuff to do, here is the only modification I need to do into the msbuild file of the build.
<UsingTask TaskName="DotNetMarche.MsBuildExtensions.Administrative.IISChangePhisicalDirTask" AssemblyFile="..sourceslibsMsBuildCustomTasksDotNetMarche.MsBuildExtensions.dll"/> <UsingTask TaskName="DotNetMarche.MsBuildExtensions.Xml.XmlPokeTask" AssemblyFile="..sourceslibsMsBuildCustomTasksDotNetMarche.MsBuildExtensions.dll"/> <Target Name="AfterDropBuild"> <Message Text="Deploy web application for $(BuildNumber)" /> <XmlPokeTask FilePath="$(DropLocation)$(BuildNumber)debug_PublishedWebsitesNorthwindWebweb.config" XPath="/connectionStrings/add[@name='Northwind']/@connectionString" NewValue='Data Source=localhostsql2008;Initial Catalog=NorthwindCiTest;user=sa;pwd=Pa$$w0rd' FailIfError='false' /> <IISChangePhisicalDirTask Username="administrator" Password="xxxxxxxxxxx" MachineName="WS2008V1" SiteName="NorthWindTest" NewPhisicalDirectory="C:DropsNorthwindTest$(BuildNumber)debug_PublishedWebsitesNorthwindWeb" /> <MSBuild Projects="$(SolutionRoot)srcDbEditionNorthwindTestNorthwindTestNorthwindTest.dbproj" Properties="OutDir=$(DropLocation)$(BuildNumber)debug;TargetDatabase=NorthwindCiTest;DefaultDataPath=C:Program FilesMicrosoft SQL ServerMSSQL10.SQL2008MSSQLDATA;TargetConnectionString=Data Source=WS2008V1SQL2008,1433%3Buser=sa%3Bpwd=Pa$$w0rd;DeployToDatabase=true;" Targets="Deploy" /> </Target>
The first two <UsingTask directive are needed to import a couple of custom msbuild task. The first is the XmlPokeTask, used to change part of an xml file. In this example you can verify how I change the connection string, because the Test Server can have a different setup, in this situation I use sa credentials, this is very bad for security, but this is only an example. In real scenario you must use integrated security.
The second task is a simple task that uses the technique described in this post, I basically change the directory used by the site NorthWindtest of a machine called WS200v1. The most important stuff here, is that drop location is on WS2008V1 machine, and since I know that the physical directory is c:drops I can simply know the real directory from the BuildNuber. This action permits me to point the test site on the latest build.
Finally since the database could be changed I need to follow the instruction of this post to deploy the data on test database. Now each time a build is triggered after the build Test machine IIS was automatically redirected to the latest version, the web.config was changed to suite the test environment, and the database is automatically upgraded. I simply did the first checkin of the project and after the build I test the site from my dev machine
The site was deployed, and I’m able to insert a record in the new empty database created by the first build.
Alk.
Tags: Team Foundation Server






November 2nd, 2009 at 4:03 pm
Where did you get the “sources\libs\MsBuildCustomTasks\DotNetMarche.MsBuildExtensions.dll” file? I would like to do the same thing but cannot find the extentions you mention. Can you post a full tfsbuild.proj file also?
November 2nd, 2009 at 8:27 pm
Hello from Russia!
Can I quote a post “No teme” in your blog with the link to you?
November 3rd, 2009 at 4:19 pm
It is an assembly that contains some tasks, if you are interested I can send you the code via E-Mail. Maybe I’ll do a post with the full code and full .proj file for full reference.
@Polprav You are welcome, no problem
Alk.
November 17th, 2009 at 2:29 pm
Nice post.
It would be nice if you can provide full code and full .proj file for reference.
This post will only be useful if you provide DLLs/Code.
Thanks
November 17th, 2009 at 3:25 pm
I’ve zipped the whole project. remember that this is a test project, I cannot give you real production project
but it should be enough.
the link is http://www.nablasoft.com/files.....eencast.7z
inside you will find a src.7z that contains the full source of the custom msbuild tasks, in the TfsBuildScreencast you can find the full dump of the tfs source directory of the project.
Please tell me if there are some problems. The only important stuff is the .proj file, and the msbuild tasks, so you should be able to reuse it if you like.
alk.