Thursday, August 25, 2011

Inline Tasks for MSBuild that work with TFS

Someone asked a question about how to do something in MSBuild the other day. They were using the UpgradeTemplate.xaml, so there build process was done almost entirely in MSBuild. What they wanted to do was fairly simple to do in a Task, but they didn't really want the overhead of creating and maintaining a Task assembly. So, I suggested an inline Task (new to MSBuild 4.0). Of course, the next question was, how can I use that with TFS. So, I started playing around and created this extremely simple inline task that prints out the Start Time of the build by reading it from the server.

This is a very simplified TfsBuild.proj that doesn't actually build anything - I took out the SolutionsToBuild and the ConfigurationsToBuild stuff. The TfsBuild.proj file looks like this:

<?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>
    <!-- Team Foundation Build Version - DO NOT CHANGE -->
    <ProjectFileVersion>2</ProjectFileVersion>
  </ProjectExtensions>

  <UsingTask
    TaskName="PrintBuild"
    TaskFactory="CodeTaskFactory"
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
    <ParameterGroup>
      <TeamFoundationServerUrl Required="True"/>
      <BuildUri Required="True"/>
    </ParameterGroup>
    <Task>
      <Reference Include="mscorlib" />
      <Reference Include="Microsoft.TeamFoundation.Build.Client" />
      <Reference Include="Microsoft.TeamFoundation.Build.Common" />
      <Reference Include="Microsoft.TeamFoundation.Client" />

      <Using Namespace="System" />
      <Using Namespace="Microsoft.TeamFoundation.Build.Client" />
      <Using Namespace="Microsoft.TeamFoundation.Build.Common" />
      <Using Namespace="Microsoft.TeamFoundation.Client" />

      <Code Type="Fragment" Language="cs">

        <![CDATA[
           Log.LogMessage("parameters to PrintBuild", MessageImportance.High);
           Log.LogMessage(TeamFoundationServerUrl, MessageImportance.High);
           Log.LogMessage(BuildUri, MessageImportance.High);
           if (!String.IsNullOrEmpty(TeamFoundationServerUrl))
           {

Read more: Jason Prickett's Blog
QR: inline-tasks-for-msbuild-that-work-with-tfs.aspx

Posted via email from Jasper-Net