Thursday, December 20, 2007

MSB4018: The "AssemblyInfo" task failed unexpectedly

If you have following error in TFS build:

MSB4018: The "AssemblyInfo" task failed unexpectedly.
C:\Program Files\MSBuild\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets(90,5):

error MSB4018: System.ArgumentException: An item with the same key has already been added,

then check all your AssemblyInfo.cs files in the solution and make sure that you do not use same assemblyAttribute twice.

For example,

instead of using

[assembly: InternalsVisibleTo("xxx")]
[assembly:InternalsVisibleTo("yyy")]

use

[assembly: InternalsVisibleTo("xxx"), InternalsVisibleTo("yyy")].

Otherwise, get source code of AssemblyInfoTask, and update dictionary class part.

Thursday, October 18, 2007

Building a ClickOnce Manifest File with Team Foundation Services Team Build

From:http://blogs.msdn.com/echarran/archive/2006/08/09/693284.aspx


Issue:


When building a ClickOnce application using Team Foundation Build Services, the goal is to modify the details contained within the .application deployment manifest file to conform to desired settings segregated by build type. This would allow Build Masters and Release Managers to build the application using different build types within Team Foundation Server and have the drops for those builds take on different deployment profiles. For example, the deployment URL for a specific debug drop would be different than its production companion. In order to change this, the information within the project can be altered so that the build process honors the settings, but this approach is not maintainable (i.e., every time the project is build, a developer has to manually edit the .csproj or .vbproj’s ClickOnce deployment settings.



Proposed Solution:


The goal is to have these settings arranged in a build type organization so a Release Manager or Build Master can simply run a build type which knows its own deployment settings or modify a set of tags to change deployment settings for a specific build type. This provides a more maintainable approach. Alternatives to accomplishing this are as follows:


Use Mage.exe – Mage.exe can be scripted or tailed to the end of the batch script that builds TFS on a nightly basis. This approach eventually resolves to MSBuild. Using MSBuild is preferred because it is a streamlined and maintainable process that does not require the involvement of Mage due to the built in capability of the GenerateApplication/DeploymentManifest task in MSBuild


Put the deployment information into the .csproj/.vbproj – This solution would require manual editing of the project before each build and does not follow best practices for release and software configuration management


Override and modify the Team Build MSBuild targets – This solution is not recommended because during various service packs the VSTS TFS team can change any of the configuration elements within the .targets associated with Team Build and it makes the implementation more esoteric and hard to maintain


Use an existing TeamBuild MSBuild plug-in target (i.e., AfterCompile, BeforeDropBuild) to specify the GenerateDeploymentManifest task – This plug-in interface to the TeamBuild target is likely to remain as it is a designed exposed interface and it is more supportable and keeps the build script simple and easy to maintain


Based on this evaluation, I chose the fourth choice.



Implementation Details:


Create a TfsBuild.proj file by creating a new build type (normal process for creating a build type in Team Client). Repeat this for each profile of build that will be required (i.e., Development, QA, Production, etc.)


Modify the build (getting latest on the using Team Foundation Source Control and checking the .proj file) to include 2 new sections following the last <ItemGroup/> node


<ItemGroup>


<EntryPoint Include ="C:\Builds\MyProject\MyProject - Debug\Sources\MyProject\MyProject.Client\obj\Debug\MyProject.Client.exe.manifest"/>


</ItemGroup>


<Target Name ="BeforeDropBuild">


<GenerateDeploymentManifest


EntryPoint="@(EntryPoint)"


DeploymentUrl="http://TFSBuildServer/MyProject/Development/MyProject.Client.exe"


Install="true"


TrustUrlParameters = "True"


MapFileExtensions="true"


UpdateEnabled="true"


UpdateInterval="3"


UpdateMode="Background"


UpdateUnit="Weeks"


OutputManifest="C:\Builds\MyProject\MyProject - Debug\Binaries\Debug\MyProject.Client.application">


<Output


ItemName="DeployManifest"


TaskParameter="OutputManifest"/>


</GenerateDeploymentManifest>


</Target>



These sections include the implementation of a target which implements the MSBuild GenerateDeploymentManifest task to create a .applicaiton manifest file based on the Entry Point (.exe) assembly being built. Specify any details that should be within the deployment manifest here.


Specify the entry point as the location of the assembly that will need the deployment manifest generated. This example assumes the path to the build is using a directory called c:\builds. If no directory is specified, the build process will error out. It assumes a local path and needs to be told in specific terms where the assembly file is located and where the deployment file should go. Specify this by including a valid path in the OutputManifest argument.


Crucial: The outputs from the build process are copied to the Binaries\[BuildType] folder, so that is the deployment file that should be modified, otherwise, the drop process will copy the original .applicaiton deployment manifest and none of the specified changes in the .proj build type will appear in the drop location.


Note that this target occurs before the Team Build BeforeDropBuild target so that we can be sure that all compilation and Team Build CoreCompile targets have been successfully implemented.


Note that we do not regenerate the assembly’s application manifest file as we would manually have to maintain application and file dependencies which are best stored within the .csproj or .vbproj itself.



Posted: Wednesday, August 09, 2006 10:03 AM
by
echarran

Filed under:


MSBuild file to publish ClickOnce using AfterCompile and MSBuild Community Tasks

From:http://geekswithblogs.net/thibbard/archive/2007/06/01/MSBuild-file-to-publish-ClickOnce.aspx
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- TO EDIT BUILD TYPE DEFINITION

To edit the build type, you will need to edit this file which was generated
by the Create New Build Type wizard. This file is under source control and
needs to be checked out before making any changes.

The file is available at -
$/{TeamProjectName}/TeamBuildTypes/{BuildTypeName}
where you will need to replace TeamProjectName and BuildTypeName with your
Team Project and Build Type name that you created

Checkout the file
1. Open Source Control Explorer by selecting View -> Other Windows -> Source Control Explorer
2. Ensure that your current workspace has a mapping for the $/{TeamProjectName}/TeamBuildTypes folder and
that you have done a "Get Latest Version" on that folder
3. Browse through the folders to {TeamProjectName}->TeamBuildTypes->{BuildTypeName} folder
4. From the list of files available in this folder, right click on TfsBuild.Proj. Select 'Check Out For Edit...'


Make the required changes to the file and save

Checkin the file
1. Right click on the TfsBuild.Proj file selected in Step 3 above and select 'Checkin Pending Changes'
2. Use the pending checkin dialog to save your changes to the source control

Once the file is checked in with the modifications, all future builds using
this build type will use the modified settings
-->
<!-- Do not edit this -->
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets" />
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<ProjectExtensions>
<!-- DESCRIPTION
The description is associated with a build type. Edit the value for making changes.
-->
<Description>
</Description>
<!-- BUILD MACHINE
Name of the machine which will be used to build the solutions selected.
-->
<BuildMachine>teamengraph</BuildMachine>
</ProjectExtensions>

<PropertyGroup>
<!-- TEAM PROJECT
The team project which will be built using this build type.
-->
<TeamProject>Goldstar</TeamProject>
<!-- BUILD DIRECTORY
The directory on the build machine that will be used to build the
selected solutions. The directory must be a local path on the build
machine (e.g. c:\build).
-->
<BuildDirectoryPath>c:\b</BuildDirectoryPath>
<!-- DROP LOCATION
The location to drop (copy) the built binaries and the log files after
the build is complete. This location has to be a valid UNC path of the
form \\Server\Share. The build machine service account and application
tier account need to have read write permission on this share.
-->
<DropLocation>\\teamengraph\drops</DropLocation>
<!-- TESTING
Set this flag to enable/disable running tests as a post build step.
-->
<RunTest>false</RunTest>
<!-- WorkItemFieldValues
Add/edit key value pairs to set values for fields in the work item created
during the build process. Please make sure the field names are valid
for the work item type being used.
-->
<WorkItemFieldValues>Symptom=build break;Steps To Reproduce=Start the build using Team Build</WorkItemFieldValues>
<!-- CODE ANALYSIS
To change CodeAnalysis behavior edit this value. Valid values for this
can be Default,Always or Never.

Default - To perform code analysis as per the individual project settings
Always - To always perform code analysis irrespective of project settings
Never - To never perform code analysis irrespective of project settings
-->
<RunCodeAnalysis>Never</RunCodeAnalysis>
<!-- UPDATE ASSOCIATED WORK ITEMS
Set this flag to enable/disable updating associated workitems on a successful build
-->
<UpdateAssociatedWorkItems>true</UpdateAssociatedWorkItems>
<!-- Title for the work item created on build failure -->
<WorkItemTitle>Build failure in build:</WorkItemTitle>
<!-- Description for the work item created on build failure -->
<DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>
<!-- Text pointing to log file location on build failure -->
<BuildlogText>The build log file is at:</BuildlogText>
<!-- Text pointing to error/warnings file location on build failure -->
<ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>
</PropertyGroup>

<Target Name="Version">
<TfsVersion LocalPath="$(SolutionRoot)">
<Output TaskParameter="Changeset" PropertyName="Revision"/>
</TfsVersion>
<Time Format="MMdd">
<Output TaskParameter="FormattedTime" PropertyName="Build" />
</Time>
</Target>
<PropertyGroup>
<Major>4</Major>
<Minor>0</Minor>
<Build>0</Build>
<Revision>0</Revision>
</PropertyGroup>

<ItemGroup>
<!-- SOLUTIONS
The path of the solutions to build. To add/delete solutions, edit this
value. For example, to add a solution MySolution.sln, add following line -
<SolutionToBuild Include="$(SolutionRoot)\path\MySolution.sln" />

To change the order in which the solutions are build, modify the order in
which the solutions appear below.
-->
<SolutionToBuild Include="$(SolutionRoot)\dev\source\code\ParaPlan\ParaPlan.sln" />

</ItemGroup>
<ItemGroup>
<!-- CONFIGURATIONS
The list of configurations to build. To add/delete configurations, edit
this value. For example, to add a new configuration, add following lines -
<ConfigurationToBuild Include="Debugx86">
<FlavorToBuild>Debug</FlavorToBuild>
<PlatformToBuild>x86</PlatformToBuild>
</ConfigurationToBuild>

The Include attribute value should be unique for each ConfigurationToBuild node.
-->
<ConfigurationToBuild Include="ReleaseAny CPU">
<FlavorToBuild>Release</FlavorToBuild>
<PlatformToBuild>Any CPU</PlatformToBuild>
</ConfigurationToBuild>
</ItemGroup>
<ItemGroup>
<!-- TEST ARGUMENTS
If the RunTest is set to true then the following test arguments will be
used to run tests.

To add/delete new testlist or to choose a metadata file (.vsmdi) file, edit this value.
For e.g. to run BVT1 and BVT2 type tests mentioned in the Helloworld.vsmdi file, add the following -

<MetaDataFile Include="$(SolutionRoot)\HelloWorld\HelloWorld.vsmdi">
<TestList>BVT1;BVT2</TestList>
</MetaDataFile>

Where BVT1 and BVT2 are valid test types defined in the HelloWorld.vsmdi file.
MetaDataFile - Full path to test metadata file.
TestList - The test list in the selected metadata file to run.

Please note that you need to specify the vsmdi file relative to $(SolutionRoot)
-->
<MetaDataFile Include=" ">
<TestList> </TestList>
</MetaDataFile>
</ItemGroup>
<ItemGroup>
<!-- ADDITIONAL REFERENCE PATH
The list of additional reference paths to use while resolving references.
For example,
<AdditionalReferencePath Include="C:\MyFolder\" />
<AdditionalReferencePath Include="C:\MyFolder2\" />
-->

</ItemGroup>
<Target Name="AfterCompile" DependsOnTargets="Version">
<MSBuild Projects="$(SolutionRoot)\dev\source\code\ParaPlan\ParaPlan\ParaPlan.csproj"
Properties="PublishDir=\\teamengraph\publish\;ApplicationVersion=$(Major).$(Minor).$(Build).$(Revision)"
Targets="Publish" />
</Target>
</Project>

Incorporating a ClickOnce Application into your Team Build

From: http://blogs.vertigosoftware.com/teamsystem/archive/2007/02/20/Incorporating_a_ClickOnce_Application_into_your_Team_Build.aspx

I found out last week that the Team Build server doesn't perform the essential Publish step that makes a ClickOnce app, well, a ClickOnce app!

But this is easy enough to fix.

Let's start with a simple Hello World ClickOnce app that has one shared DLL dependency. If we do a Team Build for this app, we get the following files in the drop folder:


OneClickApp.application
OneClickApp.exe
OneClickApp.exe.manifest
SharedLibrary.dll

Notice anything missing? To be fair, even in the Visual Studio 2005 IDE, Publish is a seperate step from Build that you must manually invoke via a different menu.



Even if you're building and publishing the project remotely on the build server, you must Publish locally at least once, so all the Publish preferences are stored in the project files.

In order to Publish a project on the Team Build server, we have to make a small edit to the tfsbuild.proj file. Under the SolutionToBuild XML element, add a SolutionToPublish element:







Check this change in, then try rebuilding. Now the drop folder contains the Publish results, too:


OneClickApp.application
OneClickApp.exe
OneClickApp.exe.manifest
SharedLibrary.dll
OneClickApp_1_0_0_0\OneClickApp.exe.deploy
OneClickApp_1_0_0_0\OneClickApp.exe.manifest
OneClickApp_1_0_0_0\SharedLibrary.dll.deploy
setup.exe

See all the new files at the bottom? With that small edit, this build is now functionally equivalent to a local Build plus Publish.

Publishing a ClickOnce app with TeamBuild

From:http://geekswithblogs.net/thibbard/archive/2007/06/01/Publishing-a-ClickOnce-app-with-TeamBuild.aspx

After much frustration, I've finally configured our TeamBuild proj file to publish our ClickOnce app, and increase the version number (kinda an important step). The Vertigo blog talks about using SolutionToPublish, but that doesn't work for all situations. Specifically, when your solution contains projects that reference other projects.
So I started playing with the MSBuild Community Tasks Project, and came up with the following Xml for my proj file:
This tells the .proj to use the community project:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\
MSBuild.Community.Tasks.Targets"/>
This defines the version numbers:
<propertygroup>
<major>4</major>
<minor>0</minor>
<build>0</build>
<revision>0</revision>
</propertygroup>

This sets the Revision to the last Changeset in our TFS server, and sets the Build to a formatted date:
<target name="Version">
<tfsversion localpath="$(SolutionRoot)">
<output taskparameter="Changeset" propertyname="Revision">
</tfsversion>
<time format="MMdd">
<output taskparameter="FormattedTime" propertyname="Build">
</time>
</target>

This tells TeamBuild to Publish this after the solution is compiled and after the Version code has been ran. It publishes the ClickOnce project to the location PublishDir with the version set in ApplicationVersion:
<target name="AfterCompile" dependsontargets="Version">
<MSBuild Projects="$(SolutionRoot)\dev\...\ParaPlan.csproj"
Properties="PublishDir=\\server\drop\;ApplicationVersion=$(Major).$(Minor).$(Build).$(Revision)"
Targets="Publish" />
</target>

The entire .proj file is here.

TeamBuild: Scheduled build using Team System

From:http://blogs.msdn.com/abhinaba/archive/2005/11/21/495179.aspx

Sorry to all the folks who read my blog for C#. This ones about Team System and specifically about the Team Build module :)
Team Build does not have any in-built scheduler and so it does not provide scheduled builds out of the box. However, it does have a command line tool to start team-builds. Any scheduler like the Windows Task Scheduler can be easily setup to use this command line Team Build utility to start builds at predetermined time. The Task Scheduler can be setup using a simple batch file or manually using the Add Scheduled task wizard that comes with Windows.
Where do I setup the scheduler?Since the scheduler will use the command line TfsBuild.exe utility, you'll need to start the scheduler on either any one of the TFS clients or on a Build Machine.
Doing it through the Scheduled Task WizardTo open Scheduled Tasks on Windows XP or Windows 2003, click Start, click All Programs, point to Accessories, point to System Tools, click Scheduled Tasks and then Add Scheduled Task. Then choose the TfsBuild.exe (ProgramFiles\Microsoft Visual Studio 8\Common7\IDE\TfsBuild.exe) as the executable and set the schedule and the account information under which you want to run the TfsBuild. At the last page ensure that the "Open advanced properties..." is checked before you hit finish...
In the dialog that opens enter the arguments in the Run text box so that its like...
"d:\Program Files\Microsoft Visual Studio 8\Common7\IDE\TfsBuild.exe" start
Doing it through a batch fileI wrote a simple batch file that makes this even easier. Copy/paste the following into a file named schbuild.bat and place it in %ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE and run schbuild.bat to see usage.@echo off
if "%1" == "" goto Help
if /i "%1" == "-h" goto Help
set server=%1
set project=%2
set buildType=%3
set schedule=%4
set startTime=%5
set startDate=%6
set schName=%2_%3
set tfsCommand="D:\PROGRA~1\MID05A~1\Common7\IDE\TfsBuild.exe start %server% %project% %buildType%"
set user=%userdomain%\%username%
echo %tfsCommand%
schtasks /create /sc %schedule% /tn %schName% /tr %tfsCommand% /st %startTime% /sd %startDate% /ru %user% /rp *
Goto Done
:Help
@echo Usage: schbuild TeamfoundationServer TeamProject BuildType Schedule StartTime StartDate
@echo.
@echo TeamfoundationServer The Team Foundation server.
@echo.
@echo TeamProject Team project name.
@echo.
@echo BuildType Build Type name.
@echo.
@echo Schedule Specifies the schedule frequency.
@echo Valid schedule types: MINUTE, HOURLY,
@echo DAILY, WEEKLY, MONTHLY, ONCE.
@echo.
@echo StartTime Time to start the build in HH:MM:SS
@echo (24 hour format)
@echo.
@echo StartDate Specifies the first date on which the
@echo task runs. The format is mm/dd/yyyy.
:Done
Sample batch file runTo start a nightly build that happens every night at 9:00p.m. use something like
SchBuild.bat MyTfsServer MyTeamProject NightlyBuildType DAILY 21:00:00 11/21/2205
Customizing the ScheduleOnce the Team Build has been scheduled through the batch file it can be easily modified using the scheduled tasks user interface. To open Scheduled Tasks use the same steps as mentioned above and then double click on the task named _ to open it and modify as required.
Published Monday, November 21, 2005 1:50 PM by abhinaba
Filed under:

Guidelines: Team Build

From: http://www.codeplex.com/TFSGuide/Wiki/View.aspx?title=Guidelines%3A++Build&referringTitle=Home

- J.D. Meier, Jason Taylor, Alex Mackman, Prashant Bansode, Kevin Jones


Index
Strategy
Use a scheduled build to produce regular builds.
Use a Continuous Integration (CI) build to get rapid feedback on check-ins.
Use a rolling build if CI builds are adversely impacting build server performance.
Use branching to reduce build breaks.
Use check-in policies to improve check-in quality.
Use build notification alerts to learn when the build has completed.


Branching
Use new Team Build Types when creating a partial branch.
Modify the paths to solutions in the TFSBuild.proj files, when creating a complete branch.


Check-in Policies
Use check-in policies to improve check-in quality.
Use check-in policies to associate work items with the build.


Continuous Integration Builds
Use a CI build to get rapid feedback on check-ins.
Use a rolling build if CI builds are adversely impacting build server performance.
Ensure that the frequency of your rolling builds is less often than the build times.


Customization
Use a custom post-build step to build an installer project.
Use MS Build Toolkit Extras to build Microsoft .NET 1.1 applications.
Use TFSBuild.proj to modify your build.
Use a custom pre-build step to build a project that has dependencies to another team project.


Deployment
On larger teams, install the build services on a separate server.


Performance
Use incremental builds to improve performance.
Avoid synchronizing redundant folders in your build.
Use workspaces to avoid checking out unwanted files and projects when doing a Team Build.
Consider using multiple build machines to improve performance.


Projects
Avoid dependencies across team projects.
Use project references instead of file references.
Use Web Deployment Project for Web applications.
Use a single-solution strategy if you are working on a small team project.
Use a partitioned-solution strategy if you are working on a large team project with multiple independent sub-projects.
Use a multiple-solution strategy if you are working on a very large team project that requires many dozens of independent sub-projects.


Scheduled Builds
Use a scheduled build to produce regular builds.


Test-Driven Development
Run code analysis on each build.
Run automated tests on each build.
Consider setting builds to fail when automated tests fail.


Work Items
Use work items to track build breaks.


Strategy
Use a scheduled build to produce regular builds.
Use CI build to get rapid feedback on check-ins.
Use a rolling build if CI builds are adversely impacting build server performance.
Use branching to reduce build breaks.
Use check-in policies to improve check-in quality.
Use build notification alerts to learn when the build has completed.


Use a Scheduled Build to Produce Regular Builds
Use a scheduled build to produce builds at regular, predictable intervals.

Generally, builds provided to your test team and to others need to be reliable and should be made available at a fixed time frequency, so that feedback on the build can be collected in a timely fashion.

The Team Build feature in Microsoft® Visual Studio® 2005 Team Foundation Server (TFS) does not support scheduled builds from the user interface. Instead, you can use the Microsoft Windows® Task Scheduler to run the TFSBuild command-line utility to start builds at a predetermined time.

To create a scheduled build

Create a TFSBuild command line as follows:

TfsBuild start <> <> <>


Place the command line in a batch file.
Create a Windows Scheduled Task that runs the batch file at your desired interval.


Additional Resources
For more information about setting up scheduled builds with Team Build, see “Chapter 9: Setting Up a Scheduled Build with Team Build” in this guide.
For more information about setting up scheduled build with TFS, see “How To – Set Up a Scheduled Build in Visual Studio Team Foundation Server” in this guide.


Use a Continuous Integration Build to Get Rapid Feedback on Check-ins
You should use CI builds to provide your development team with rapid feedback on any breaking changes and on the quality of the build after each check-in. This helps the development team to fix the build issues quickly and can be used as a tool to improve the quality of your code.

Although Team Foundation Server 2005 does not provide a CI solution out of box, it does provide the framework for you to implement your own CI build solution.

For more information on setting up a CI build with TFS, see “How To – Set Up a Continuous Integration Build in Visual Studio Team Foundation Server.” This How To article uses the solution provided by the Microsoft Visual Studio Team System (VSTS) development team. The solution installs a Web service that runs under an account that has access to the TFS server. Team Foundation Server is able to send an e-mail message or call a Web service when specific events occur. This event mechanism is used by the CI solution to register a Web service with the CheckinEvent event,** so that whenever a check-in occurs, the Web service initiates a Team Build.


Additional Resources
For more information, see “Chapter 8: Setting Up a Continuous Integration Build with Team Build” in this guide.
For more information about setting up a CI build, see “How To – Set Up a Scheduled Build with Visual Studio Team Foundation Server” in this guide.
For more information about how to use the VSTS CI solution, see “Continuous Integration Using Team Foundation Build” at http://msdn2.microsoft.com/en-us/library/ms364045(VS.80).aspxTo download the VSTS CI solution MSI, go to http://download.microsoft.com/download/6/5/e/65e300ce-22fc-4988-97de-0e81d3de2482/ci.msiFor more information about agile development and CI in TFS, see “Extend Team Foundation Server To Enable Continuous Integration” at http://msdn.microsoft.com/msdnmag/issues/06/03/TeamSystem/default.aspx


Use a Rolling Build if CI Builds Are Adversely Impacting Build Server Performance
Building immediately after every check-in is the simplest CI strategy and generally provides you with the most rapid feedback. However, if check-ins occurs rapidly enough to overwhelm your build server, you should use a rolling build approach where you build after a specified number of check-ins or after a specified time period. To decide if you need to use a rolling build, determine the following:

Length of your Team Build in minutes
Average frequency of check-ins in minutes
Time window during which frequent check-ins occur

If the length of the build is longer than the average frequency of check-ins, your builds will run continuously because the first build will not complete before the next check-in occurs, which will start another build. If check-ins continue to occur before each build is complete, this impacts the performance of the build server and will block other builds (such as scheduled builds) from being started. Review the time window during which frequent check-ins occur and determine if CI builds will impact the delivery of scheduled builds or other important Team Builds.


Additional Resources
For more information, see “Chapter 8 – Setting Up a Continuous Integration Build with Team Build” in this guide.


Use Branching to Reduce Build Breaks
To help avoid build breaks, you should use a Development branch for active development and a Main branch for your integration build.

The following is an example of what your branch structure might look like after you have created a Development branch:

Development – Development Branch
Source
Main – Integration Branch
Source
Other Assets folders

Keep the following recommendations in mind when working with a release branch:

When to branch. If you are creating daily builds and are having problems with build stabilization and integration, you should create both a main and a development branch to ensure greater predictability of your daily builds. You may also want to consider more stringent check-in policies to improve check-in quality.
When not to branch. If you are only creating CI builds, or your daily builds are already predictably stable, you might not need the extra overhead of an integration branch.
Permissions on branch:
The Main branch permissions should be read/write for developers responsible for merging and integration, but read-only for everyone else.
The Dev branch permissions should be read/write for everyone.
Build frequency in branch:
Daily builds on the Main branch.
CI builds on the Dev branch.
Testing focus on branch:
Perform integration, performance, and security testing on the Main branch.
Perform feature and quick feedback testing on the Dev branch.

Use the Main branch as a staging area for integrating changes that have been checked into the development branch. Perform all active development in the Dev branch, and integrate non-breaking changes into the Main branch.


Additional Resources
For more information on defining a branching and merging strategy, see “Chapter 5 – Defining Your Branching and Merging Strategy” in this guide.
For an introduction to branching and merging, see “Branching and Merging Primer” at http://msdn2.microsoft.com/en-us/library/aa730834(VS.80).aspx
For more information about branching, see “How to: Branch Files and Folders” at http://msdn2.microsoft.com/en-us/library/ms181425(VS.80).aspx
For more information about merging, see “How to: Merge Files and Folders” at http://msdn2.microsoft.com/en-us/library/ms181428(VS.80).aspx
For additional descriptions of how to branch and merge in Visual Studio 2005, see “Branching and Merging Team Foundation Source Control” at http://msdn2.microsoft.com/en-us/library/ms181423(VS.80).aspx


Use Check-in Policies to Improve Check-in Quality
You should use a combination of code analysis and testing policies to improve check-in quality. For example, use the supplied testing policy to ensure that specific tests are executed and passed prior to allowing source to be checked into TFS source control. You can also configure a code analysis policy to help ensure that your code meets certain quality standards by ensuring that security, performance, portability, maintainability, and reliability rules are passed.

By enforcing this type of check-in policy in addition to policies that enforce coding standards and guidelines, you can test your code against specific code quality issues.

To enforce a code analysis check-in policy for a team project, you right-click your team project in Team Explorer, point to Team Project Settings, and then click Source Control. Click the Check-in Policy tab, click Add, and then select and configure the appropriate policy.


Additional Resources
For more information about creating and using a custom check-in policy, see “How To – Step Through Creating Custom Check-in Policies for TFS” in this guide.
To learn how to customize a check-in policy, see “Walkthrough: Customizing Check-in Policies and Notes” at http://msdn2.microsoft.com/en-us/library/ms181281(VS.80).aspx
To see sample code that will disallow selected patterns on check-in, see “Checkin Policy to Disallow Certain Patterns” at http://blogs.msdn.com/jmanning/archive/2006/02/02/523125.aspxTo see sample code that will enforce comments on check-in, see “Sample Checkin Policy: Make Sure the Comment Isn’t Empty” at http://blogs.msdn.com/jmanning/archive/2006/01/21/515858.aspxTo learn how to register a new check-in policy, see “I’ve Made a New Check-In Policy! How Do I Add It?” at http://blogs.msdn.com/jmanning/archive/2006/02/07/526778.aspx


Use Build Notification Alerts to Learn When the Build Has Completed
To keep track of your build process, you can create alerts that send e-mail messages to you or to others when a build has completed.

This is important because it provides quick turnaround among teams. For example, if the test team is notified by e-mail of a completed build, they can start their test pass without having to wait for manual instructions.


Additional Resources
For more information about build notifications, see “How to: Receive Build Notification E-Mail” at http://msdn2.microsoft.com/en-us/library/ms181725(VS.80).aspx
For further information about build notifications, see “How to: Add or Edit Alerts” at http://msdn2.microsoft.com/en-us/library/ms181335(VS.80).aspx


Branching
Use new Team Build Types when creating a partial branch.
Modify the paths to solutions in the TFSBuild.proj files, when creating a complete branch.


Use New Team Build Types When Creating a Partial Branch
When you create a branch that contains a subset of the solutions in your team project, you might need to create new build types in order to build successfully.

There are two types of partial branches:

A partial branch that does not include branching of any build types. This would occur within a team project, and would simply branch solution and source files but would not branch any of the TeamBuildTypes folders into new folders.
A partial branch that includes branching of build types. This would occur within a team project, and would branch some of the TeamBuildTypes subfolders (that is, build types) in addition to other folders containing the relevant solution and source files.

If you create a partial branch that does not include Team Build Types all of the existing Team Builds will continue to work, but you will need to create a new Team Build Type if you want to build the branch. Create new build types by using the Team Build Wizard in order to build the code in the new branch. These new build types will point to the new branch location and may also point to the parent location for any solutions that must be included in the build but that were not branched.

If you create a partial branch that includes Team Build Types, the build types that are copied over with the branch will point to the original, parent branch locations and therefore will not allow you to build the new branch. Modify the branched build types so that they point to the new branched code locations.


Additional Resources
For more information about how to update your build type, see “How to: Update Build Types on Branched Team Projects” at http://msdn2.microsoft.com/en-us/library/ms252500(VS.80).aspx


Modify the Paths to Solutions in the TFSBuild.proj Files, When Creating a Complete Branch
When you create a new branch, including the Team Build Types, the paths in the build types still point to the previous location. In order for the build to work on the new branch, you must update the paths in the build type project files so that they reference the new path locations created after the branching operation.

When you create a full branch, you also branch the build types. The build types contain references to folders from the original source control tree. To have these build types refer to the branch folders, you must edit the folder references in these files.

To perform the update, check out the build types from the branch you want to modify, apply the updates, and then commit the changes to the branch.


Additional Resources
For more information about how to update your build types, see “How to: Update Build Types on Branched Team Projects” at http://msdn2.microsoft.com/en-us/library/ms252500(VS.80).aspx


Check-in Policies
Use check-in policies to improve check-in quality.
Use check-in policies to associate work items with the build.


Use Check-in Policies to Improve Check-in Quality
Use a combination of code analysis and testing policies to improve check-in quality. For example, use the supplied testing policy to ensure that specific tests are executed and passed prior to allowing source to be checked into TFS source control. You can also configure a code analysis policy to help ensure that your code meets certain quality standards by ensuring that security, performance, portability, maintainability, and reliability rules are passed.

By enforcing this type of check-in policy in addition to policies that enforce coding standards and guidelines, you can test your code against specific code quality issues.


Additional Resources
For more information about creating and using a custom check-in policy, see “How To: Step Through Creating Custom Check-in Policies for TFS” in this guide.
To learn how to customize a check-in policy, see “Walkthrough: Customizing Check-in Policies and Notes” at http://msdn2.microsoft.com/en-us/library/ms181281(VS.80).aspx
To see sample code that will disallow selected patterns on check-in, see “Check-in Policy to Disallow Certain Patterns” at http://blogs.msdn.com/jmanning/archive/2006/02/02/523125.aspxTo see sample code that will enforce comments on check-in, see “Sample Check-in Policy: Make Sure the Comment Isn’t Empty” at http://blogs.msdn.com/jmanning/archive/2006/01/21/515858.aspxTo learn how to register a new check-in policy, see “I’ve Made a New Check-In Policy! How Do I Add It?” at http://blogs.msdn.com/jmanning/archive/2006/02/07/526778.aspx


Use Check-in Policies to Associate Work Items with the Build
Set the Work Items check-in policy to force developers to associate their check-in with a work item.

If a build breaks, it is important that you know what change sets are associated with this build and what work items those change sets are associated with. With this knowledge, you can identify the developer responsible for checking in the changed code and the area of the project on which he or she is working.

For a build to be associated with a set of completed work items, each check-in must be associated with a work item. These check-ins are represented as change sets associated with the build, and it is possible to trace from build to change set to work item.


Additional Resources
For more information about creating and using a custom check-in policy, see “How To: Step Through Creating Custom Check-in Policies for TFS” in this guide.
To learn how to customize a check-in policy, see “Walkthrough: Customizing Check-in Policies and Notes” at http://msdn2.microsoft.com/en-us/library/ms181281(VS.80).aspx


Continuous Integration Builds
Use a CI build to get rapid feedback on check-ins.
Use a rolling build if CI builds are adversely impacting build server performance.
Ensure that the frequency of your rolling builds is less often than the build times.


Use a CI Build to Get Rapid Feedback on Check-ins
You should use Continuous Integration builds to provide your development team with rapid feedback on any breaking changes and quality of the build after each check-in. This helps the development team to fix the build issues in a timely manner and can be used as a tool to improve the quality of your code.

Although Visual Studio 2005 Team Foundation Server does not provide a CI solution out of the box, it does provide the framework for you to implement your own CI build solution.

For more information on setting up a CI build with TFS, see “How To: Set Up a Continuous Integration Build in Visual Studio Team Foundation Server.” This How To article uses the solution provided by the VSTS development team. The solution installs a Web service that runs under an account that has access to the TFS server. Team Foundation Server is able to send an e-mail message or call a Web service when specific events occur. This event mechanism is used by the CI solution to register a Web service with the CheckinEvent event,** so that whenever a check-in occurs, the Web service initiates a Team Build.


Additional Resources
For more information about CI builds, see “Chapter 8 – Setting Up a Continuous Integration Build with Team Build” in this guide.
For more information about setting up a CI build, see “How To – Set Up a Continuous Integration Build with Visual Studio Team Foundation Server” in this guide.
For more information about how to use the VSTS CI solution, see “Continuous Integration Using Team Foundation Build” at http://msdn2.microsoft.com/en-us/library/ms364045(VS.80).aspxTo download the Visual Studio Team System CI solution MSI, go to http://download.microsoft.com/download/6/5/e/65e300ce-22fc-4988-97de-0e81d3de2482/ci.msiFor more information about agile development and CI in TFS, see “Extend Team Foundation Server to Enable Continuous Integration” at http://msdn.microsoft.com/msdnmag/issues/06/03/TeamSystem/default.aspx


Use a Rolling Build if CI Builds Are Adversely Impacting Build Server Performance
Building immediately after every check-in is the simplest CI strategy and will generally give you the most rapid feedback. However, if check-ins occurs rapidly enough to overwhelm your build server, you should use a rolling build approach where you build after a specified number of check-ins or after a specified time period. To decide if you need to use a rolling build, determine the following:

Length of your Team Build in minutes
Average frequency of check-ins in minutes
Time window during which frequent check-ins occur

If the length of the build is longer than the average frequency of check-ins, your builds will run continuously because the first build will not complete before the next check-in occurs, which will start another build. If check-ins continue to occur before each build is complete, it will impact the performance of your build server and will delay other builds, such as scheduled builds. Review the time window during which frequent check-ins occur and determine if CI builds will impact the delivery of scheduled builds or other important Team Builds.


Additional Resources
For more information about setting up CI builds, see “Chapter 8 – Setting Up an Continuous Integration Build with Team Build” in this guide.


Ensure That the Frequency of Your Rolling Builds Is Less Often than the Build Times
It is important to determine the rolling build time interval to ensure an efficient build process. If the frequency of the rolling build is less than the time it takes to complete a build, it ensures that your build machine will be available for other build types between your rolling build intervals.

To determine the ideal rolling build interval, divide the average frequency of check-ins by the length of your build. For instance, if you have a build that takes 10 minutes and you average a check-in every 5 minutes, you could set a check-in interval of two check-ins and a timeout period of 10 minutes. This would help ensure that the build is complete before the next build kicks off. If you notice excessive load on your build server, you can increase these values.


Additional Resources
For more information about CI builds, see “Chapter 8 – Setting Up a Continuous Integration Build with Team Build” in this guide.


Customization
Use a custom post-build step to build an installer project.
Use MS Build Toolkit Extras to build Microsoft .NET 1.1 applications.
Use TFSBuild.proj to modify your build.
Use a custom pre-build step to build a project that has dependencies to another team project.


Use a Custom Post-Build Step to Build an Installer Project
Because Team Build does not support setup projects by default, you should use a custom post-build step to compile the setup project and copy the binaries to the build drop location.


Additional Resources
For more information, see “Walkthrough: Configuring Team Foundation Build to Build a Visual Studio Setup Project” at http://msdn2.microsoft.com/en-us/library/ms404859(VS.80).aspx


Use MS Build Toolkit Extras to Build Microsoft .NET 1.1 Applications
Team Build does not support .NET 1.1 applications by default. The MSBuild Extras – Toolkit for .NET 1.1 (MSBee) allows .NET 1.1 builds but requires that your projects and solutions be upgraded to Visual Studio 2005. If you cannot upgrade to Visual Studio 2005 projects and solutions, you can use a custom post-build step to compile the .NET 1.1 applications.


Additional Resources
To download MSBee, go to http://www.codeplex.com/MSBee
For more information about creating a custom post-build step to compile a .NET 1.1 application, see Nagaraju’s blog entry at http://blogs.msdn.com/nagarajp/archive/2005/10/26/485368.aspx


Use TFSBuild.proj to Modify Your Build
To modify information about the build?such as the build server, drops location, or build directory?you edit the TFSBuild.proj file.

The TFSBuild.proj file contains much of the information needed to execute a Team Build. This information includes the build locations and whether the build should perform static code analysis and unit tests. To modify the build, you edit the TFSBuild.proj file.

To edit the TFSBuild.proj file

Check out the file from source control.
Update the build information in the file.
Check the file back in, committing the changes.

The next time the build is executed, it will use the amended build data.


Additional Resources
For more information about customizing Team Foundation Build, see “Customizing Team Foundation Build” at http://msdn2.microsoft.com/en-us/library/ms400688(VS.80).aspx


Use a Custom Pre-build Step to Build a Project That Has Dependencies to Another Team Project
Team Build does not support building solutions that cross team projects. To enable this, you must customize the TFSBuild.proj file to check out the code you need from the other projects on which your build depends.


Additional Resources
For more information, see “Working with multiple team projects in Team Build” at http://blogs.msdn.com/manishagarwal/archive/2005/12/22/506635.aspx
For more information about customizing Team Foundation Build, see “Customizing Team Foundation Build” at http://msdn2.microsoft.com/en-us/library/ms400688(VS.80).aspx


Deployment
On larger teams, install the build services on a separate server.


On Larger Teams, Install the Build Services on a Separate Server
Large Team Builds can take a long time and use up significant server resources. If you run your builds on your Team TFS server, this impacts the reliability, performance, and scalability of the server.

To improve the performance of your build and reduce load on your application tier, it is recommended that you run builds on a dedicated build server.


Additional Resources
To download the Team Foundation Installation Guide, or for more information about installing TFS and Team Build, go to http://www.microsoft.com/downloads/details.aspx?FamilyId=E54BF6FF-026B-43A4-ADE4-A690388F310E&displaylang=en


Performance
Use incremental builds to improve performance.
Avoid synchronizing redundant folders in your build.
Use workspaces to avoid checking out unwanted files and projects when doing a Team Build
Consider using multiple build machines to improve performance.


Use Incremental Builds to Improve Performance
By default, Team Build cleans out the directory it uses to perform the build before it checks out the complete source code tree needed for the build. Team Build also removes and re-initializes the workspace used to check out the sources for the build. To improve performance, you can set Team Build to only get sources that have changed since the last Team Build.

If the amount of source needed for a build is large and the build server is remote from the TFS server, the source code checkout could take a long time to execute. In such a case, you should consider using an incremental build. To perform the incremental build, you need to set several values in your TFSBuild.proj file should be true. You need to:

Stop Team Build from cleaning the local build folder and sources folder.
Stop Team Build from re-creating the workspace used for the build.
Configure the Team Build to only get the changed sources from source control.

To perform an incremental build

Create a new build type to represent the incremental build.
Check out for edit the TFSBuild.proj file associated with the incremental build type you just created.
Add the following section just before the closing element in TFSBuild.proj:

true
true
false

These settings accomplish the following:

SkipClean. Setting SkipClean to true ensures that the build will not clean out the local build and sources folder.
SkipInitializeWorkspace. Setting SkipInitializeWorkspace to true ensures that the build will leave the existing workspace in-place for the build machine.
ForceGet. Setting ForceGet to false ensures that the build will only get updated source, rather than getting all source for the workspace.


Additional Resources
For more information, see “Practices at a Glance – Team Build” in this guide.
For more information about configuring an incremental build, see “How to: Configure Team Foundation Build for an Incremental Build” at http://msdn2.microsoft.com/en-us/library/aa833876(VS.80).aspx


Avoid Synchronizing Redundant Folders in Your Build
You should scale down your workspace mapping or cloak folders that are not needed as part of the build.

When you execute a Team Build, the server retrieves all of the files it needs from source control. The files that are retrieved are defined by the workspace that is used to create the Team Build Type. Some of the files that are mapped into the workspace may not be needed. You can change your workspace definition to reduce the folders included, or you can cloak unnecessary files so that they are not retrieved as part of the build.

For example, the default mapping for a new project is $/TeamProject. If all your source files are under $/TeamProject/foo/bar/foobar/sources, you should map only that directory.

To cloak files beneath your workspace mapping, you can edit the WorkspaceMapping.xml file that is created when the Team Build Type is created and is used to define the folders that are retrieved when performing the build. You can cloak files and folders that are not needed as part of the build. Folder cloaking is preferred because individual file cloaking can introduce maintenance overhead.

To cloak folders

Check out WorkspaceMapping.xml from source control.
Add the appropriate cloak entries to this file.
Check in WorkspaceMapping.xml.

The following example ensures that the documentation folder will not be retrieved from source control during a Team Build:







Additional Resources
For more information about cloaking folders in a workspace, see “How to: Cloak and Decloak Folders in a Workspace” at http://msdn2.microsoft.com/en-us/library/ms181378(VS.80).aspxFor more information about making Team Build ignore folders, see “How to make ‘Team Build’ skip getting certain folders?” at http://blogs.msdn.com/manishagarwal/archive/2005/10/13/480584.aspxFor more information about the WorkspaceMapping schema, see “Schema for the WorkspaceMapping.xml file” at http://blogs.msdn.com/buckh/archive/2007/02/28/schema-for-the-workspacemapping-xml-file.aspx


Use Workspaces to Avoid Checking Out Unwanted Files and Projects When Doing a Team Build
Team Build checks out your sources in order to execute the build. If you have a large source tree for a project, checking out the sources can be very time-consuming. If you are only building part of the team project, you should ensure that only the necessary sources are checked out.

If you have a large team project, it will contain multiple Visual Studio solutions, each of which is used to build a separate part of the team project. When you create a Team Build Type, you specify the solution that Team Build will use. If you specify a solution file without specifying a workspace, Team Build will check out all of the sources in the team project before performing a build.

To check out only the sources you need, you must first define a workspace. Before creating the Team Build Type, you first define a workspace and only map the solution you want to build to that workspace. When you define the Team Build Type, select the workspace you have defined and then select the solution. In this way, only the sources defined in that workspace will be checked out.


Additional Resources
For more information about creating a Team Build Type, see “Walkthrough: Creating a Build Type in Team Foundation Build” at http://msdn2.microsoft.com/en-us/library/ms181286(VS.80).aspxFor more information about why Team Build checks out all the source code in a workspace, see “Why does Team Build sync all sources in spite of my selecting only a subset of solutions?” at http://blogs.msdn.com/anutthara/archive/2005/12/07/500923.aspx


Consider Using Multiple Build Machines to Improve Performance
If you have multiple build types all executing on a single build server, the server could become overwhelmed. In such a situation, you should consider executing different build types on different build servers.

A build can take a long time to execute, especially if the build is for a large project. If you are using CI or frequent scheduled builds, the build server might not be able to keep up with the volume of builds being generated.

You can install multiple build servers to distribute the load among different servers. Assign different build types to each server to even out the build load.


Additional Resources
For more information, see “Chapter 7 – Team Build Explained” in this guide.


Projects
Avoid dependencies across team projects.
Use project references instead of file references.
Use Web Deployment Project for Web applications.
Use a single-solution strategy if you are working on a small team project.
Use a partitioned-solution strategy if you are working on a large team project with multiple independent sub-projects.
Use a multiple-solution strategy if you are working on a very large team project that requires many dozens of independent sub-projects.


Avoid Dependencies Across Team Projects
In general, you should avoid dependencies that cross team projects and instead try to keep all related/dependent solutions/projects under same team project. This reduces the need for build script customization. If you have a dependency, use project references to define it, or branch the dependency from a shared project into your project. You should avoid file references because they are more difficult to manage.


Additional Resources
For more information about creating a workspace, see “How to: Create a Workspace” at http://msdn2.microsoft.com/en-us/library/ms181384(VS.80).aspxFor more information about editing a workspace, see “How to: Edit a Workspace” at http://msdn2.microsoft.com/en-us/library/ms245466(VS.80).aspx
For more information about branching, see “How to: Branch Files and Folders” at http://msdn2.microsoft.com/en-us/library/ms181425(VS.80).aspx


Use Project References Instead of File References
If you need to reference another assembly in the same Visual Studio solution, you should use a Visual Studio project reference. By using project references, you enable Visual Studio to do a few things automatically for you, such as keeping build configuration synchronized (debug/release) and tracking versioning and rebuilding of components as necessary when assembly versions change.


Additional Resources
For more information about project references, see “Project References” at http://msdn2.microsoft.com/en-us/library/ez524kew(VS.80).aspx


Use Web Deployment Project for Web Applications
Web deployment projects are associated with a Visual Studio Web Site project or Web Application project. They allow you to manage build settings as well as a variety of other settings common to ASP.NET Web applications. For instance, the deployment project gives you easy access to Web.config, connection strings, and virtual directories, and allows you to more easily deploy the compiled Web application to the hosting server.


Additional Resources
For more information, see “Visual Studio 2005 Web Deployment Projects” at http://msdn2.microsoft.com/en-us/asp.net/aa336619.aspx


Use a Single-Solution Strategy if You Are Working on a Small Team Project
If you work on a small team, consider using a single Visual Studio solution to contain all of your projects. This structure simplifies development because all of the code is available when you open the solution. This strategy also makes it easy to set up references, because all references are between projects in your solution. You may still need to use file references to reference third-party assemblies, such as purchased components, that are outside your solution.


Additional Resources
For more information, see “Chapter 3 – Structuring Projects and Solutions in Source Control” in this guide.


Use a Partitioned-Solution Strategy if You Are Working on a Large Team Project with Multiple Independent Sub-Projects
If you work on a large team, consider using multiple solutions, each representing a subsystem in your application. Developers can use these solutions to work on smaller parts of the system without having to load all code across all projects. You should design your solution structure so that any projects that have dependencies are grouped together. This enables you to use project references rather than file references. Consider creating a master solution file that contains all of the projects, if you want to use this to build the entire application.

Note: If you are building with Team Build (which relies upon MSBuild), it is possible to create solution structures that do not include all referenced projects. As long as the entire solution has been built first, generating the binary output from each solution, MSBuild will be able to follow project references outside the bounds of your solution and build successfully. Solutions created in this way will not build from the Visual Studio build command, but will only work with Team Build and MSBuild.


Additional Resources
For more information, see “Chapter 3 – Structuring Projects and Solutions in Source Control” in this guide.


Use a Multiple-Solution Strategy if You Are Working on a Very Large Team Project That Requires Many Dozens of Independent Sub-Projects
If you work on a very large solution requiring many dozens of projects, you may run up against solution scalability limits. In this scenario, break your application into multiple solutions but do not create a master solution for the entire application because all references inside each solution are project references. References to projects outside of each solution (for example, to third-party libraries or projects in another sub-solution) are file references. This means that there can be no “master” solution. Instead, a script must be used that understands the order in which the solutions must be built. One of the maintenance tasks associated with a multiple-solution structure is ensuring that developers do not inadvertently create circular references between solutions. This structure requires complex build scripts and explicit mapping of dependency relationships. In this structure, it is not possible to build the application in its entirety within Visual Studio. Instead, you can use TFS Team Build or MSBuild directly.


Additional Resources
For more information, see “Chapter 3 – Structuring Projects and Solutions in Source Control” in this guide.


Scheduled Builds
Use a scheduled build to produce regular builds.


Use a Scheduled Build to Produce Regular Builds
You should use a scheduled build to produce builds at regular, predictable intervals.

In general, builds provided to test teams and others need to be reliable and should be made available at a fixed time frequency, so that feedback on the build can be collected in a timely fashion.

Although the Team Build feature in TFS does not support scheduled builds from the user interface, you can use the Microsoft Windows Task Scheduler to run the TFSBuild command utility to start builds at a predetermined time.

To create a scheduled build

Create a TFSBuild command line as follows:

TfsBuild start <> <> <>


Place the command line in a batch file.
Create a Windows Scheduled Task that runs the batch file at your desired interval.


Additional Resources
For more information, see “Chapter 9 – Setting Up Scheduled Build with Team Build” in this guide.
For more information about setting up scheduled build, see “How To – Set Up a Scheduled Build with Visual Studio Team Foundation Server” in this guide.


Test-Driven Development
Run code analysis on each build.
Run automated tests on each build.
Consider setting builds to fail when automated tests fail.


Run Code Analysis on Each Build
Use code analysis as part of the build to improve build quality. You can configure a code analysis step in the build to help ensure that your code meets certain quality standards, ensuring that security, performance, portability, maintainability, and reliability rules are passed.

To turn on code analysis for a build type, you can either select the code analysis check box in the Team Build Type wizard when you create the new Team Build Type, or you can modify the TFSBuild.proj file after the build type has been created.

To enable code analysis in the TFSBuild.proj file

If you want all projects to run code analysis, regardless of project settings, change the tag to Always.
If you want to run code analysis on each project based on project settings, change the tag to Default.


Additional Resources
For more information about automatic code analysis as part of a build, see “How To – Automatically Run Code Analysis with Team Build in Visual Studio Team Foundation Server” in this guide.
For more information about code analysis tools, see “Guidelines for Using Code Analysis Tools” at http://msdn2.microsoft.com/en-us/library/ms182023(VS.80).aspx


Run Automated Tests on Each Build
Run automated tests to automatically gain feedback on build quality after every build. In order to create a test list to associate with the build you must have either Visual Studio Test Edition or Visual Studio Team Suite installed. In order to run automated tests on the build server you must have either Visual Studio Developer Edition, Visual Studio Test Edition, or Visual Studio Team Suite installed on the build server.

To run automated tests as part of the Team Build process

Create one or more automated tests that you want to run with the build.
Use the Test Manager to create a Test List.
Use the Test Manager to group tests into the new Test List by dragging and dropping the tests from the Test View to the Test List in the Test Manager.
Create a new Team Build Type.
Select the check box to run automated tests.
Select the test project within which your tests and test list were created.
Select the test list you want to run.


Additional Resources
For more information about automatically running build verification tests, see “How to: Configure and Run Build Verification Tests (BVTs)” at http://msdn2.microsoft.com/en-us/library/ms182465(VS.80).aspx
For more information about how to run automated build tests without Visual Studio Test Edition or a VSMDI file, see “How to run tests in a build without test metadata files and test lists (.vsmdi files)” at http://blogs.msdn.com/buckh/archive/2006/11/04/how-to-run-tests-without-test-metadata-files-and-test-lists-vsmdi-files.aspx


Consider Setting Builds to Fail When Automated Tests Fail
When a build fails because of compilation errors, a work item is created to track the failure and the build is marked as failed. When an automated test fails, however, the build does not fail. The test failure is converted into a warning and the build continues.

You may want to fail the build if an associated automated test fails. You may also want to generate a work item automatically to track the test failure.

To fail the build upon test failure

Open the Microsoft.TeamFoundation.Build.targets file from Program Files\MSBuild\Microsoft\VisualStudio\v8.0\TeamBuild.
Check out for edit and open the TFSBuild.proj file for the Team Build Type you want to have failed upon test failure.
Copy the RunTestWithConfiguration target from Microsoft.TeamFoundation.Build.targets to the end of the TFSBuild.proj file, just before the closing tag.
Modify the ContinueOnError attribute from true to false. - Note: There will be two test tool tasks. Modify the end-to-end task in order to only modify the behavior of builds on the build server. The desktop build task is used when building on a developer’s desktop.
If you want to create a work item when the build fails, modify the RunTestWithConfiguration by adding an OnError element just before the closing tag The OnError element should look like the following:


Alternatively, if you want all Team Build Types to fail upon test failure, you can modify Microsoft.TeamFoundation.Build.targets directly. This change will modify behavior for all Team Build Types.

The solution recommended above is straightforward to implement but is not guaranteed to continue working for future versions of Visual Studio. If you would like to implement a solution that is guaranteed to continue working after upgrade, see Aaron Hallberg’s blog entry, “Determining Whether Tests Passed in Team Build,” at http://blogs.msdn.com/aaronhallberg/archive/2006/09/21/determining-whether-tests-passed-in-team-build.aspx


Additional Resources
For more information about setting up a build to create a work item upon test failure, see “Create Workitems for Test Failures in TeamBuild” at http://blogs.msdn.com/nagarajp/archive/2005/10/14/481290.aspx
For more information about a solution that is guaranteed to continue working after a Visual Studio upgrade, see “Determining Whether Tests Passed in Team Build” at http://blogs.msdn.com/aaronhallberg/archive/2006/09/21/determining-whether-tests-passed-in-team-build.aspx


Work Items
Use work items to track build breaks.


Use Work Items to Track Build Breaks
If Team Build fails, it automatically creates a work item to track that failure. By default, the work item will be assigned to ‘Active’ and the title will inform you that there has been a build failure. You should assign this work item to the responsible developer or build manager in order to fix the build and resolve the problem.

The build task in TFSBuild.proj that defines this work item looks like the following:



If you would like to customize the work item that is created (for instance, to assign it to a specific developer or to set severity and priority), you can modify the WorkItemFieldValues field.


Additional Resources
For more information about customizing the build failure work item, see “Team Foundation Build Tasks” at http://msdn2.microsoft.com/en-us/library/ms243778(vs.80).aspx


Build Resources
For more information about Team Builds in general, see “Overview of Team Foundation Build” at http://msdn2.microsoft.com/en-us/library/ms181710(VS.80).aspx