In the last project management practice "Five" auto-compiling and publishing Web site, we explained how to use msbuild+robocopy+webdeployment to build and deploy the Web site, and today, let's look at how to use MSBuild +svn to come from a synchronous database.
First, put the database files and database log files in our project into a directory, put it in the Startkitdb directory, and then create a new text file named Startkitdb in the directory, modify the extension proj, in fact, in theory any extension can, and then, Use Notepad or another program to open the file, copy the following content to it, and save it.
<?xml version= "1.0" encoding= "Utf-8"?>
<project defaulttargets= "All" xmlns= "http://schemas.microsoft.com/developer/msbuild/2003" >
<!--need to introduce MSBuild Community Tasks----
<import project= "$ (msbuildextensionspath) \msbuildcommunitytasks\msbuild.community.tasks.targets"/>
<PropertyGroup>
<!--database connection string, which can be modified as needed--
<connectionstring>server=.;i ntegrated security=true</connectionstring>
</PropertyGroup>
<ItemGroup>
<!--database Files--
<dbfiles include= "STARTKITDB.MDF; Startkitdb_log.ldf "/>
</ItemGroup>
<target name= "All" >
<!--restart SQL Server service--
<servicecontroller servicename= "MSSQLServer" action= "Restart"/>
<!--separate databases--
<exec command= "Osql-s. -e-n-Q " EXEC sp_detach_db ' startkitdb ', ' True ' " ' Ignoreexitcode= "false"/>
<!--stop SQL Server Services--
<servicecontroller servicename= "MSSQLServer" action= "Stop"/>
<!--delete old versions of database files--
<delete files= "C:\StartKitDB\$ (dbfiles)"/>
<!--Copy the latest version of the database file to the specified location--
<copy sourcefiles= "@ (dbfiles)" destinationfolder= "C:\StartKitDB"/>
<!--start SQL Server service--
<servicecontroller servicename= "MSSQLServer" action= "Start"/>
<!--append the latest version of the database file to the database---
<exec command= "Osql-s. -e-n-Q " EXEC sp_attach_db @dbname = n ' startkitdb ', @filename1 = N ' C:\StartKitDB\StartKitDB.mdf ', @filename2 = N ' C:\StartKitDB\ Startkitdb_log.ldf ' " " Ignoreexitcode= "false"/>
</Target>
</Project>
Of course, if we want to: when we submit the latest database files and log files to the server, automatically detach the old version of the database from the server, while attaching the latest version of the database, then we have to use CCNet and SVN server, so we first need to store the database files, Log files and Startkitdb folders for StartKitDB.proj files are included in our version control. However, if we simply add this file to the code base of our Startkit project, then when we commit the database update, we will automatically compile the entire Startkit project, and at this point our project may not be updated, so we will separate the database and project into two code bases.
We follow the project management Practice Tutorial II, the source code control, using VISUALSVN server to add a code base "Repository" Startkitdb, and then, using TortoiseSVN to move the above three files to the SVN server, and finally, According to the project management practice "three" daily construction of the explanation, add a project "project" on the ccnet, must modify the corresponding file path according to the actual situation, Configure the ProjectFile node value under the Tasks sub-node MSBuild to the new StartKitDB.proj file above us.
Note: Do you configure the location of the database files on the SVN server to be removed from the ccnet in the same location in the StartKitDB.proj file above, for specific reasons? You can think for yourself first!
OK, it's done! You can submit a database to SVN server once, try to see if there is any effect, how? It's a success! Hey...
This method is suitable for use in the development process, if we have already deployed the project or has been delivered to the user, then the user may have added and updated a lot of data, and we developed at the latest version of SVN also inconsistent, this time to consider the security of user data, We may need to give the user a database update script, and to ensure that the user's data security, then, how to do? I in Visual Studio 2008 How to compare the schema of the two database "schema" and the data "and" and do a more detailed explanation, we can do a reference!
If you're unfamiliar with what I'm explaining, it's recommended that you look at this series of tutorials from the beginning: A series of project management practice tutorials.
Transferred from: http://www.cnblogs.com/ttzhang/archive/2008/11/11/1331034.html
Project management Practice "Six" automatic synchronization database Using Visual Studio with Source Control System to synchronize database automatically "