TFS Check-In Validation Tool

Team Build, Team System 2008 October 21st, 2008

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

Team Build and ClickOnce

MSBuild, Team Build September 13th, 2008

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=\\qa1Srv\drops\publishedVers\ "
  Targets="Publish" />
</Target>

How To Deploy Data Dude Project Changes using Team Foundation Build

Data Dude, MSBuild, Team System 2008 April 28th, 2008

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)\SolutionName\ProjectName\ProjectName.dbproj"       Properties="Configuration=Default;OutDir=$(SolutionRoot)\..\binaries\Default\" 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=ServerName\InstanceName;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.

Remove Items From ItemGroups In MSBuild

MSBuild, Team Build March 25th, 2008

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

Team Build, Team System, Team System 2008 March 13th, 2008

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.

Custom Build Number In Team Build

MSBuild, Team Build December 13th, 2007

Many users want to modify the default build number of Team System Team Build which looks like: <Build-Type-Name>_<Date>.XXX.

You can change it by writing a custom task and call it in the BuildNumberOverrideTarget target of the MSBuild file. In this example the task will generate a unique build number based on current time:

using System;using Microsoft.Build.Utilities;using Microsoft.Build.Framework;

namespace MaorDavidBlog.Samples.MSBuild{    public class BuildNameGenerator:Task    {

        private string _buildName;

        public override bool Execute()

        {                        _buildName = DateTime.UtcNow.ToString();            return true;        }

        [Output]        public string BuildName

        {            get { return _buildName; }        }

    }}

The attribute “Output” indicates that BuildName property is output of the custom task.

Then, register the task in TFSBuild.proj file.

<!-- Add using task line just after import statement - - ><UsingTask  TaskName="MaorDavidBlog.Samples.MSBuild.BuildNameGenerator"   AssemblyFile="$(MyCustomTasks)\MaorDavidBlog.Samples.MSBuild.dll"/>

<! -- Override the target towards the end of proj file - - ><Target Name = "BuildNumberOverrideTarget" >    <BuildNameGenerator>             <Output TaskParameter="BuildName"            PropertyName="BuildName"/>     </BuildNameGenerator> </Target>

Next time you’ll execute your build, you’ll see your custom build name.

Building VS 2008 projects with TFS 2005

Team Build, Team System, VSTS December 8th, 2007

When you try to build VS 2008 solutions with Team Foundation Build 2005 you get:

MSB5014 - File format version is not recognized.

I posted about it and one of the comments (by Eran Kampf) linked to Mitch Denny’s approach. Customers ask me about it a lot and this is the best approach to deal with the problem.

Buck Hodges says that the best “workaround” is to upgrade to TFS 2008. But not all of you will upgrade soon to 2008. For you, Mitch’s approach is the best.

Technorati Tags: ,

TFS Build Lab 1.0 Released

MSBuild, Team Build, Team System, Team System 2008 November 4th, 2007

UntitledTFSBuildLab 1.0 is released on CodePlex.

This is a project to simplify the day to day operations when using automated builds on TFS.

This project handles common Team System issues such as:

  • Continuous integration builds
  • Scheduled builds
  • Build queuing
  • Event notifications
  • Manual and automated build cleanup

What features included in V1.0:

Service

  • Automatic rescheduling when adding new scheduled trigger.
  • A report for displaying statistics from the triggers and retention policies.
  • Support for overriding build script parameters both for CI and queued builds.
  • Support for only deleting the build drops.
  • Support for configuring retention policies based on build quality.
  • Performance improvements by introducing caching

Admin Client

  • Added feedback when deleting multiple builds.
  • Support for forcing reaching on the server.
  • Support for overriding build script parameters on queued builds.
  • Support for overriding build script parameters on triggers.
  • Added range parameters when listing log entries to limit the result data.

Checkin Policies

  • Removed the need for TfsBuildLab when using the restricted paths policy.
Technorati Tags: , ,

Build a labeled version with TeamBuild

Team Build, Team System, Team System 2008 October 24th, 2007

This is the 3rd post in the series of posts about MSBuild. You can read them at:

  1. Introduction to MSBuild.
  2. Create custom task to MSBuild - step by step.

As you know, TeamBuild builds the latest version by default. At the Target “CoreGet” in the MSBuild script (you can find it at Microsoft.TeamFoundation.Build.targets file), it gets the latest version from source control to the local workspace on the build machine and build the source.

To build a labeled source you have to set a value to the Version property of the Get task in this target.

So, all you need to do is to override the CoreGet target in the TfsBuild.proj file (it’s better than override it in the target file because if you do so, this change will affect all builds on the machine…):

   1:  <Target Name="CoreGet"
   2:        Condition=" '$(IsDesktopBuild)'!='true' "
   3:        DependsOnTargets="$(CoreGetDependsOn)" >
   4:  
   5:      <!-- Get all the latest sources from the given workspace-->
   6:      <Get Condition=" '$(SkipGet)'!='true' "
   7:          Workspace="$(WorkspaceName)"
   8:          Recursive="$(RecursiveGet)"
   9:          Force="$(ForceGet)"
  10:          Version="$(VersionToBuild)" />
  11:  </Target>

The property in line 10 is the property that do the work…

You can declare the $VersionToBuild variable at the PropertyGroup element or by passing this value from the .rsp file. The easiest way is to declare it at the PropertyGroup element.

   1:  <PropertyGroup>
   2:      <VersionToBuild>M_1.0.0.223</VersionToBuild>
   3:  </PropertyGroup>

That’s all!

Enjoy.

Technorati Tags: ,

Create custom task for MSBuild - Step by Step

MSBuild, Team Build, Team System, Team System 2008 October 10th, 2007

This is the 2nd post in the msbuild posts series. The first post was an introduction to MSBuild and give you tasting of the basics.

In order to extend Team Foundation Build by plugging in your own logic and tasks, you must write a custom task and use it in your build script (the .proj file).

Custom MSBuild task must be implemented as a .NET class that implements the ITask interface, which is defined in the Microsoft.Build.Framework.dll assembly. You can implement your task in the following two ways:

  1. Derive your class directly from ITask and implement the methods on this interface. or
  2. Derive your class from the helper class, Task (an abstract base class that is a default implementation for BuildEngine and HostObject properties) which is defined in the Microsoft.Build.Utilities.dll assembly. Choosing this option makes it easier to log events from your task.

In both cases you must implement (ITask) or override (Task) it’s Execute method. I override this mwthod with a very simple logic to just log a string value to the Build log as you see below.

Step 1 - Creating project

Create Class Library project with a class and a reference to Microsoft.Build.Utilities assembly. I’ll derive the class from the Task abstract class and override the Execute method.

Step 2 - Writing the task

Execute function must return true if task has executed successfully otherwise it must return false. Now I will add my code to the Execute method - this is my logic which I want to be executed during the build process. I also add a property to the class (Message) and set an attribute to it [Required] (line 29) - this indicates that msbuild must pass a parameter to the task. The Log ( line 17,24) object I use is the LoggingHelper of the Build Utilities (defined at Microsoft.Build.Utilities.dll )

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using Microsoft.Build.Utilities;
   5:  using Microsoft.Build.Framework;
   6:  
   7:  namespace MSBuildTasks
   8:  {
   9:      public class MyTask:Task
  10:      {
  11:          private string message;
  12:  
  13:          public override bool Execute()
  14:          {
  15:              try
  16:              {
  17:                  Log.LogMessage(
  18:                      String.Format("This is the message from my task: {0}",
  19:                      message));
  20:                  return true;
  21:              }
  22:              catch
  23:              {
  24:                  Log.LogError("Error occured in my task!");
  25:                  return false;
  26:              }
  27:          }
  28:  
  29:          [Required]
  30:          public string Message
  31:          {
  32:              get { return message; }
  33:              set { message = value; }
  34:          }
  35:  
  36:      }
  37:  }

Now compile the project.

Step 3 - Registering the task in MSBuild file

Now we need to import and register this custom task to the MSBuild file we want to extend (This is because MSBuild must know how to locate the assembly that contains the task class.) . We’ll do it by editing the .proj file of the build and add a <UsingTask> element which is a direct child of root <Project> element.  This element has a TaskName attribute to get the name of the task class and an AssemblyFile attribute to get the name or address of the assembly where this class is implemented in.

<UsingTask TaskName="MSBuildTasks.MyTask" AssemblyFile="C:\Work\Projects\Samples\MSBuild\MSBuildTasks\bin\Debug\MSBuildTasks.dll"/>

Step 4 - Calling the task from MSBuild

Calling the task depends on the point in the build process where we want to call. We should choose the point in the process that we want to call the task and add the following under it:

   1:  <Target Name="MyTaskTarget">
   2:      <MyTask Message="Hi MSBuild" />
   3:    </Target>

Line 2 calls the task. The message here is the required parameter to pass to the task.

Step 5 - Running the MSBuild file

After all of that you should run the msbuild file.

This is my MSBuild file (.proj extension)

<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  <UsingTask TaskName="MSBuildTasks.MyTask"            AssemblyFile="C:\MSBuildTasks\MSBuildTasks.dll" />  <Target Name="MyTaskTarget">    <MyTask Message = "Hi MsBuild"/>  </Target></Project>

This is the output of the example.

msbuild

Enjoy!!

See you in the next post of the MSBuild series.

Technorati Tags:
blank