How to: Create an Automated Build and Deployment Solution with Team Foundation Server Team Build

Microsoft Visual Studio Team System provides a mechanism to implement continuous building and testing using the Build function under a Visual Studio Team System project. The Build function sets up and runs MSBuild on a targeted computer that is running the Team Foundation Server build agent.

This topic walks you through setting up a Build definition and setting up a computer to run the defined build. First, it explains the SharePoint Web Solution Package, and then it demonstrates how to automatically build and deploy SharePoint solutions with Visual Studio extensions for Windows SharePoint Services version 1.3. Next, it shows you how to set up the Team Foundation Server build agent to run the continuous testing. Then, it defines the build and attaches the build definition to the Team Foundation Server build agent. The procedures in this topic require the following to be installed on your computer:

  • Visual Studio Team System 2008
  • Visual Studio extensions for Windows SharePoint Services version 1.3

The following sections summarize the steps that are required to automatically build and deploy the SharePoint solutions:

  • Understanding the Web Solution Package
  • Building, Packaging, and Deploying the SharePoint Solution
  • Creating a Team Foundation Server Build Agent
  • Creating a TFSBuild.proj File

The next sections describe these steps.

Understanding the Web Solution Package

A Web solution package (WSP) is the primary way to deploy custom SharePoint features and components in Windows SharePoint Services 3.0. A WSP is a CAB file that has a .wsp file name extension. It contains a manifest that is named Manifest.xml and all the SharePoint solution artifacts that are necessary for deploying a SharePoint solution.

You can manually create a Web solution package and create and maintain the manifest file and the feature files yourself if you do not want to use the Visual Studio extensions for Windows SharePoint Services 1.3. After you are ready to deploy your SharePoint solution, use the Makecab.exe tool (MakeCab) to create the WSP. For more information about how to manually create WSP files, see Creating a Solution on MSDN.

Both the Training Management and Partner Portal applications' SharePoint solutions are created with Visual Studio extensions for Windows SharePoint Services 1.3. This means that Visual Studio extensions for Windows SharePoint Services 1.3 generates the manifest and the feature XML files. One advantage of using Visual Studio extensions for Windows SharePoint Services 1.3 is that developers do not need to maintain a large number of XML files.

The rest of this topic discusses how to create an automated build and deployment system. The code for the pertinent files and targets is included within the appropriate sections.

Building, Packaging, and Deploying the SharePoint Solution

Building and deploying a SharePoint solution is simplified if you create your Visual Studio project with Visual Studio extensions for Windows SharePoint Services 1.3. First, click Build Solution on the Visual Studio Build menu. After the Visual Studio solution compiles, click Deploy Solution on the Build menu. This deploys your solution to the SharePoint site you specified at the Start Action "start browser with URL" in the Project Property Page Debug section.

You can also create the WSP files without actually deploying the solution. To do this, right-click the Visual Studio extensions for Windows SharePoint Services project, and then click Package. The package command creates the WSP file and the Setup.bat file in the bin\debug or bin\release folder of your project.

You can use a command line script to package your solution. You can package all the Visual Studio extensions for Windows SharePoint Services projects into a solution or you can package an individual project in a solution. The following command packages an entire solution that is named YourVstsSolution.sln:

devenv YourVstsSolution.sln /Deploy debug /Package

The following command packages an individual project as a solution:

devenv YourVstsSolution.sln /Deploy debug /Package YourVseWSSProject

Creating a Team Foundation Server Build Agent

For information about how to create a Team Foundation Server build agent, see How to: Create and Manage Build Agents on MSDN.

Creating a TFSBuild.proj File

For information about how to create a Team Foundation Server build project file, see Walkthrough: Creating a Build Definition in Team Foundation Build on MSDN.

An Example TFSBuild.proj File

The following code is the TFSBuild file for the Partner Portal application's BVTs. These tests run each night. The build file performs the following tasks:

  1. It runs ClearContosoSetup.bat to remove data left over from the previous test run.
  2. It removes the old source folder so it can get the new source files from Team Foundation Server.
  3. It removes any read-only attributes in the sources files before it creates a solution package.
  4. It runs ContosoSetup.bat to install the reference implementation.
  5. It runs the test lists Partners, PartnerPortal, and Services in /Test/PartnerPortal /Contoso.PartnerPortal.BVT.vsmdi. This file is generated when the solution file is opened.

The following XML is the TFSBuild file.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />
  <ProjectExtensions>
    <ProjectFileVersion>2</ProjectFileVersion>
    <Description></Description>
    <BuildMachine>SPG-2K8-BVT32</BuildMachine>
  </ProjectExtensions>
  <PropertyGroup>
    <TeamProject>SPG</TeamProject>
    <BuildDirectoryPath>C:\Documents and Settings\v-appave\Local Settings\Temp\1\SPG\SPGv2-2k8-BVT32</BuildDirectoryPath>
    <DropLocation>\\SPG-2K8-BVT32\BuildStageFolder</DropLocation>
    <RunTest>true</RunTest>
    <RunCodeAnalysis>Never</RunCodeAnalysis>
    <WorkItemType>Bug</WorkItemType>
    <WorkItemFieldValues>System.Reason=Build Failure;System.Description=Start the build using Team Build</WorkItemFieldValues>
    <WorkItemTitle>Build failure in build:</WorkItemTitle>
    <DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>
    <BuildlogText>The build log file is at:</BuildlogText>
    <ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>
    <UpdateAssociatedWorkItems>true</UpdateAssociatedWorkItems>
    <AdditionalVCOverrides></AdditionalVCOverrides>
    <CustomPropertiesForClean></CustomPropertiesForClean>
    <CustomPropertiesForBuild></CustomPropertiesForBuild>
  </PropertyGroup>
  <ItemGroup>
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../../../Setup/SetupSource/ContosoSetup.sln">
        <Targets></Targets>
        <Properties></Properties>
    </SolutionToBuild>
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../../../Source/Microsoft.Practices.SPG2/Microsoft.Practices.SPG2.sln">
      <Targets></Targets>
      <Properties></Properties>
    </SolutionToBuild>
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../../../Test/Contoso.PartnerPortal.BVT/Contoso.PartnerPortal.BVT.sln">
        <Targets></Targets>
        <Properties></Properties>
    </SolutionToBuild>
  </ItemGroup>
  <ItemGroup>
    <ConfigurationToBuild Include="Release|Any CPU">
        <FlavorToBuild>Release</FlavorToBuild>
        <PlatformToBuild>Any CPU</PlatformToBuild>
    </ConfigurationToBuild>
  </ItemGroup>
  <ItemGroup>
    <MetaDataFile Include="$(BuildProjectFolderPath)/../../../../Test/Contoso.PartnerPortal.BVT/Contoso.PartnerPortal.BVT.vsmdi">
        <TestList>Partners;PartnerPortal;Services</TestList>
    </MetaDataFile>
  </ItemGroup>
  <PropertyGroup>
    <workspaceSetupFolderPath>C:\Bvt2\Trunk</workspaceSetupFolderPath>
  </PropertyGroup>
  <Target Name="BeforeEndToEndIteration">

    <Message Text="Step:1***** Run ClearContosoSetup.bat to clean previous test"/>
    <Exec Command="$(workspaceSetupFolderPath)\setup\ClearContosoSetup.bat" IgnoreExitCode="true" />

    <Message Text="Step:2***** Remove Source folder so we can get new source files from TFS"/>
    <RemoveDir Directories="C:\BVT2\Trunk\" ContinueOnError ="true"/>
  </Target>
  <Target Name="AfterCompile" Condition=" '$(IsDesktopBuild)'!='true'">

    <Message Text="Step:3***** Removing Read only attributes in sources files before create package"/>
    <Exec WorkingDirectory="C:\BVT\Drops" Command="RemoveReadOnly.bat" />

    <Message Text="Step:4***** Executing ContosoSetup.bat to install contoso RI "/>
    <Exec Command="$(workspaceSetupFolderPath)\setup\ContosoSetup.bat" IgnoreExitCode="true" />
  </Target>
  <ItemGroup>
  </ItemGroup>
</Project>

Home page on MSDN | Community site