Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get BuildNumber in .proj (MSBuild) using TFS server

Tags:

msbuild

We use TFS 2010 with VS 2010 for PHP web projects. Actually we do not have any .proj or .sln file, so i have made my own to make builds, it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
    <ItemGroup>
        <ZipFiles Include="**\*.*"/>
    </ItemGroup>

    <Target Name="Zip" >
        <Zip Files="@(ZipFiles)" ZipFileName="$(OutDir)myzip.zip" />
    </Target>

    <Target Name="Build" DependsOnTargets="Zip">
        <Message Text="My Build Complete - $(BuildNumber) - $(TeamProject) - $(BuildProperties)" />
    </Target>
    <Target Name="AfterBuild">
        <MakeDir Directories="Testing" />
        <Message Text="My AfterBuild- $(BuildNumber) "></Message>
    </Target>
</Project>

I have configured build numbers in build definition in VS as "$(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)" , and drop folder on network path is created correctly.

The problem is that $(BuildNumber) or $(TeamProject) or $(BuildProperties) are empty. Also it seems that "My Afterbuild" is never executed.

Why are my variables empty and how to get build number from build definition as specified?

like image 964
Hrvoje Kusulja Avatar asked Sep 07 '11 07:09

Hrvoje Kusulja


1 Answers

To run AfterBuild targets:

<DefaultTargets="AfterBuild" />

<Target Name="Build" DependsOnTargets="Zip">

<Target Name="AfterBuild" DependsOnTargets="Build">

For me is not clear why Zip target should be executed before the Build target?

EDIT:

You have to update template file defaultTemplate.XAML by adding manually BuildNumber to the MSBuild command line so command Line would be like:

<mtbwa:MSBuild CommandLineArguments="[String.Format(&quot;
        /p:SkipInvalidConfigurations=true 
        /p:BuildNumber={1} {0}&quot;, 
        MSBuildArguments, 
        BuildDetail.BuildNumber)]" />

See the original article regarding this trick: TFS2010 – Where is $(BuildNumber)?

like image 66
sll Avatar answered Nov 15 '22 00:11

sll