MSBuild + Team Build 2008 Presentation

You can download MSBuild & Team Build 2008 presentation.

TFS Check-In Validation Tool

New tool was released on CodePlex called TFS Check-in Validation Tool.

This tool provides the ability to have a checkin validating by a build prior to being checked in.  This is similar to a feature in TFS 2010 called Gated Checkin, which is integrated into VS and TFS (more info in this video). With both of these the goal is to prevent build breaks from being checked in by validating them beforehand.

If you really like it and are interested in doing something similar with TFS 2008 (before TFS 2010) comes out, you can check out this new project on CodePlex: http://www.codeplex.com/BuddyBuild.

It is not a part of TFS and the implementation is unrelated to the TFS 2010 Gated checkin feature.

image

<TestContainer> Works With WebTest & LoadTest In Team Build 2008 With SP1

The new <TestContainer> item in Team Build 2008 in a great way to run tests without test metadata file (*.vsmdi).

You can specify the following to run all unit tests found in assemblies matching the pattern *.Tests.dll and even specify .LoadTest and .WebTest files as well:

<ItemGroup>
  <TestContainer Include="$(Outdir)*.Tests.dll" />
  <TestContainer Include="$(Outdir)WebTest1.webtest" />
  <TestContainer Include="$(Outdir)LoadTest1.loadtest" />
</ItemGroup>

But if you try to run it in Team Build 2008, you will get an error like: Could not load file or assembly.

That’s because the task tries to do an Assembly.LoadFrom() on whatever files you include in the <TestContainer> item. This obviously fails because .LoadTest and .WebTest are XML files, not assemblies.

This problem has been solved in TFS 2008 SP1. All you need to do is to apply the TFS SP1 patch to the build machine (If you don’t want, it’s not necessary to install TFS SP1 on TF Server to get the fix).

Team Build and ClickOnce

The other day I got a question: How can I deploy an app via ClickOnce using Team Build?

There is not out of box way to do that, but we can do it with a simple workaround:

we should overload the target AfterCompile in TFSBuild.Proj to call MSBuild Task Publish and can pass the PublishDir property:

<Target Name="AfterCompile">
  <MSBuild
  Condition=" '@(SolutionToBuild)'!='' "
  Projects="@(SolutionToBuild)"
  Properties="Configuration=%(ConfigurationToBuild.FlavorToBuild);
    Platform=%(ConfigurationToBuild.PlatformToBuild);
    SkipInvalidConfigurations=true;
    VCBuildOverride=$(MSBuildProjectDirectory)TFSBuild.vsprops;
    FxCopDir=$(FxCopDir);OutDir=$(OutDir);
    PublishDir=$(OutDir);
    ReferencePath=$(ReferencePath);
    TeamBuildConstants=$(TeamBuildConstants);
    $(CodeAnalysisOption);PublishDir=\qa1SrvdropspublishedVers "
  Targets="Publish" />
</Target>

Configure Team Foundation Build for an Incremental Build

A question I got today: “How can I configure my Team Build for an incremental build?”.

So, it’s simple.

Team Build 2005

Add the PropertyGroup definition to the end of the TFSBuild.proj file, before the closing </project> tag.

Set the following properties:

   <PropertyGroup>      <SkipClean>true</SkipClean>      <SkipInitializeWorkspace>true</SkipInitializeWorkspace>      <ForceGet>false</ForceGet>   </PropertyGroup>

Team Build 2008

Set IncrementalBuild property to true. To do it, add the PropertyGroup definition to the end of the TFSBuild.proj file, before the closing </project> tag.

   <PropertyGroup>      <IncrementalBuild>true</IncrementalBuild>   </PropertyGroup>

Source – msdn:

Team Build 2005: http://msdn.microsoft.com/en-us/library/aa833876(VS.80).aspx

Team Build 2008: http://msdn.microsoft.com/en-us/library/aa833876.aspx

How To Deploy Data Dude Project Changes using Team Foundation Build

When you want to build and deploy database projects with team build you need to edit the database project file and the Team Build file. That’s because database projects store any non-default values for the TargetDatabase, TargetConnectionString, and DefaultDataPath properties in a <ProjectName>.dbproj.user file.  *.user files are not checked into version control in order to let every user use different values.

 

Step 1 – Modify build project file (team build .proj file)

Open the BuildDefinition.proj file, and at the bottom of the file, between the </ItemGroup> element and the </Project> element, add the following:

<Target Name="AfterDropBuild">
<MSBuild Projects="$(SolutionRoot)SolutionNameProjectNameProjectName.dbproj"
Properties="Configuration=Default;OutDir=$(SolutionRoot)..binariesDefault" Targets="Deploy" />
</Target>

 

Step 2 – 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.

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=ServerNameInstanceName;Integrated Security=True;Pooling=False</TargetConnectionString>

If TargetDatabase and TargetConnectionString already contain empty elements, you should overwrite those entries.

 

More into at the msdn page.

How To: Delete Build Agent In TFS 2008

I’m working on my TechEd demos which includes DB Projs and MSBuild + Team Build .I needed to remove one of my build agents.

To remove a build agent, navigate to to the Build Menu,  or the Build Explorer.  Click on Manage Build Agents in order to remove/edit/add a build agent.

BuildAgent

In order to use the Build Menu, you must first open the Team Explorer. Otherwise, the Manage Build Agents will not be part of the menu.

BuildAgent

Remove Items From ItemGroups In MSBuild

The ability to remove entries from ItemGroups is one of the new features of MSBuild 3.5.

To remove an Item from an ItemGroup in MSBuild 2.0 you would have to create a new ItemGroup from the old one and skip the Item that you needed removed.

In MSBuild 3.5 we can achieve it by using the Remove parameter.

Example:

<ItemGroup>    <Files Include="a.cs" />    <Files Include="b.cs" />    <Files Include="c.cs" />    <Files Include="d.cs" />    <Files Include="e.cs" />    <Files Include="f.cs" />    <Files Include="g.cs" /></ItemGroup>

Some times we want to restrict some data from this group in a target. In order to do it,  we should use the Remove parameter:

<ItemGroup>    <Files Remove="a.cs" />    <Files Remove="e.cs" />    <Files Remove="f.cs" /></ItemGroup>

Read more at msdn.

Running Tests On TFS Build Machine

Often I asked “What do I need to install on the TFS build machine in order to run tests?”

Well, the answer is simple.

In VSTS 2005 you have to install the Tester or Suite editions on the Build Machine to run tests (even Unit Tests).

In VSTS 2008 installing the Developer Edition version is enough.

Building .NET 3.0 projects from Team Foundation Build 2005 not supported

Building .NET 3.0/3.5 projects from Team Foundation Build 2005 not supported. Team Foundation Build 2005 will always invoke the 2.0 Framework’s MSBuild.exe, which does not support building solutions that target the 3.5 Framework.  (The 3.0 Framework shipped with Vista, while the 3.5 Framework is shipping with VS 2008.)

The 3.5 Framework includes new MSBuild bits which allow multi-targeting – i.e. MSBuild 3.5 can target the 2.0 Framework.

We can convert our solution to VS2008 beta 2 and target the solution to .NET framework 2.0. It’s not enough. When we’ll try to build this solution with Team Foundation Build 2005, we’ll get an error MSB5014 – File format version is not recognized.

The MSBuild blog has great post about MSBuild, Orcas, and Multi-targeting. Find it here.

%d bloggers like this: