In the last project management practice "Five" automated compilation and publishing site, we explained how to use msbuild+robocopy+webdeployment to compile and deploy the Web site, today, let's take a look at how to use the MSBuild +svn to come from the dynamic synchronization database.
First, put the database files and database log files in our project under a directory, place it in the Startkitdb directory, and then create a new text file named Startkitdb in the directory, modify the extension to Proj, and in fact, any extension name can, in theory, Using 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, you can modify--> as needed
<connectionstring>server=.;i ntegrated security=true</connectionstring>
</PropertyGroup>
<ItemGroup>
<!--database file-->
<dbfiles include= "STARTKITDB.MDF; Startkitdb_log.ldf "/>
</ItemGroup>
<target name= "All" >
<!--restart SQL Server services-->
<servicecontroller servicename= "MSSQLSERVER" action= "restart"/>
<!--separate database-->
<exec command= "Osql-s. -e-n-Q " EXEC sp_detach_db ' startkitdb ', ' True ' " Ignoreexitcode= "false"/>
<!--stop SQL Server service-->
<servicecontroller servicename= "MSSQLServer" action= "Stop"/>
<!--delete the old version of the database file-->
<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 services-->
<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 need to use the CCNet and SVN server, so we first need to store the database files, Log files and StartKitDB.proj files in the Startkitdb folder, into our version control. However, if we simply add this file to our Startkit project's code base, we will automatically compile the entire Startkit project when we submit the database update, and our project may not be updated, so we have to separate the database and the project into two code bases.
We use VISUALSVN server to add a code base "Repository" Startkitdb, and then use TORTOISESVN to move the three files above to the SVN server as explained in the Project Management Practice Tutorial II, source code control, and finally, According to the project management practice of "three" daily construction of the explanation, add a project in CCNet "project", must modify the corresponding file path according to the actual situation, Configure the ProjectFile node value under the node MSBuild of tasks to our newly created StartKitDB.proj file.
Note: You configure the ccnet to move the database files from the SVN server to the same location in the StartKitDB.proj file above, for specific reasons. You can think about it yourself first.
OK, it's done. You can submit a database to the SVN server and try to see if there is any effect. It's a success. Hey...
This approach is suitable for use in the development process, if we have deployed the project or have been delivered to the user, then the user may have added and updated a lot of data, and we develop the latest version on SVN also inconsistent, this time, considering the security of user data, We may need to give the user the database update script, and to ensure that the user's data security, then what to do. How do I compare the schema "schema" and "data" of the two databases in Visual Studio 2008 and do a more detailed explanation, you can make a reference.
If you're unfamiliar with what I'm explaining, it's a good idea to look at this series of tutorials from the beginning: a series of tutorials on project management practice.