Share via


How to: Deploy Changes using Team Foundation Build

You can build and deploy your database from within Visual Studio, by using MSBuild, or by using Team Foundation Build. If you want to build and deploy your database project in a build lab environment, you would use Team Foundation Build. To use Team Foundation Build, you must have a computer on which you have it installed. For more information, see Overview of Team Foundation Build.

The process to deploy changes by using Team Foundation Build is as follows:

  • Create a build type.

  • Modify the build project file manually to override the standard AfterDropBuild target.

  • Modify the database project file manually to specify the target database and connection.

  • Check in the updated files.

  • Use the new build type to deploy your database project.

Before you can deploy changes using Team Foundation Build, you must:

  • Have a database project with its properties set.

  • Check the database project into version control.

To Create a Build Type

To create a build type

  1. Open Visual Studio 2005 with Team Explorer.

  2. Open the solution that contains the database project that you want to deploy.

  3. Create a build type. For more information, see How to: Create a New Build Type. When you create the build type, specify the current solution to be built. If you have not created a custom project configuration, click the Default configuration.

    Next you will modify the BuildType.proj file.

To Modify the Build Project File

To deploy the database project, you must override the AfterDropBuild target with the SqlDeploy task.

To modify the build project file

  1. Check out the BuildType.proj file from version control. If you are using Team Foundation source control, open Source Control Explorer, expand the team project, and expand the TeamBuildTypes folder to find the build project files.

  2. Open the BuildType.proj file in the editor of your choice.

  3. At the bottom of the file, between the </ItemGroup> element and the </Project> element, add the following:

    <Target Name="AfterDropBuild">
      <MSBuild Projects="$(SolutionRoot)\SolutionName\ProjectName\ProjectName.dbproj" Properties="Configuration=Default;OutDir=$(SolutionRoot)\..\binaries\Default\" Targets="Deploy" />
    </Target>
    

    Replace SolutionName with the name of the solution that contains the database project, and replace ProjectName with the name of the database project. If you are not using the Default configuration for your database project, replace Default with the name of the appropriate project configuration both in Configuration and in OutDir.

    Team Foundation Build copies files to a drop location that is usually a network share. If you want to deploy the database from that location instead of from the build machine, you would instead use the following:

    <Target Name="AfterDropBuild">
      <MSBuild Projects="$(SolutionRoot)\SolutionName\ProjectName\ ProjectName.dbproj" Properties="Configuration=Release;OutDir=$(DropLocation)\$(BuildNumber)\Release\" Targets="Deploy"/>
    </Target>
    
  4. Save the changes to BuildType.Proj.

To Modify the Database Project File

The target connection and database are stored in the ProjectName.dbproj.user file, which is user specific and not typically checked in to version control. You require those settings to deploy your database. Therefore, you must modify the ProjectName.dbproj file manually to specify the target connection and database.

To modify the database project file

  1. Check the ProjectName.dbproj file out from your version control system.

  2. On the File menu, click Close Solution. This step is necessary because you cannot modify a project file that is in an open solution.

  3. On the File menu, point to Open, and click File.

  4. Browse to the folder that contains the database project file (ProjectName.dbproj), and double-click ProjectName.dbproj.user.

  5. Copy the lines that contain the definitions for the TargetDatabase and TargetConnectionString properties from the section in the ProjectName.dbproj.user file for the configuration that you want to build. These lines will resemble the following:

    <TargetDatabase>MyTargetDatabaseName</TargetDatabase>
    <TargetConnectionString>Data Source=ServerName\InstanceName;Integrated Security=True;Pooling=False</TargetConnectionString>
    

    Note

    The name of the database project is used if you do not specify the name of a target database.

  6. Copy those two entries to the Clipboard.

  7. On the File menu, point to Open, and click File.

  8. Browse to the folder that contains the database project file (ProjectName.dbproj), and double-click ProjectName.dbproj.

  9. Scroll down to the PropertyGroup for the configuration that you want to deploy using Team Foundation Build.

  10. Paste the entries that you copied to the Clipboard into the project file. If TargetDatabase and TargetConnectionString already contain empty elements, you should overwrite those entries.

  11. On the File menu, click Save ProjectName**.dbproj**.

To Check in the Updated Files

Team Foundation Build uses the version of the database project that is checked into version control. Before you use that version to deploy your database, you must check in the changes that you made to the build project and the database project file.

To check in the updated files

  1. On the File menu, point to Source Control, and click Check In Pending Changes.

  2. Follow the instructions for your version control system to complete the check in for the build project and the database project file.

To Deploy your Database

You have now configured the build type and set up the database project for use with Team Foundation Build. You can perform a test build to verify whether your database deploys successfully.

To deploy your database

  1. In Team Explorer, expand the Team Builds folder, right-click the build type that you created to deploy the database project, and click Build Team Project TeamProjectName.

    The Build dialog box appears.

  2. Confirm that the values in the Build type, Build machine, and Build directory boxes are all appropriate, and then click Build.

    The build starts, and the build summary appears. If there are no errors, when the build is finished, the summary reads "Successfully Completed."

  3. If there are build errors, you can click the link to the build log to determine the cause of the error. Correct the error, and then re-build the database.

See Also

Tasks

How to: Configure Database Projects for Build and Deployment

Concepts

Overview of Team Foundation Build
An Overview of Database Build and Deployment
Terminology Overview of Team Edition for Database Professionals

Other Resources

Understanding the Team Foundation Build Browser
How to: Run Database Unit Tests from Team Foundation Build