6

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?

Hrvoje Kusulja
  • 925
  • 1
  • 11
  • 25

1 Answers1

11

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)?

sll
  • 61,540
  • 22
  • 104
  • 156
  • Yes, sorry about mistake with DefaultTargets. Anyway first zip, then Build which does only Message. Also on lot of forums the $(BuildNumber) is standard same as $(OutDir), but it does not work in my case, maybe i need something else ? How can i get buildnumber from build definition ? , Also AfterBuild should be executed again after Build is complete, no need in my case, someone told that then will BuildNumber variable be available , but it is not, you can ignore then AfterBuild. Also i can not pass any arguments to msbuil, since it is Build agent server on TFS 2010 server. – Hrvoje Kusulja Sep 07 '11 at 08:05
  • Are you have access to the process template file defaultTemplate.XAML ? – sll Sep 07 '11 at 08:17
  • yes i have, i can made a copy and modify it. tell me what i need to do – Hrvoje Kusulja Sep 07 '11 at 09:00
  • @Hrvoje Kusulja: see edit part of my answer, you need to add manually /p:BuildNumber={1} parameter and pass it as BuildDetail.BuildNumber – sll Sep 07 '11 at 09:05
  • Ok, thank you I see. I have modified in this way, however i get: MSBUILD : error MSB1001: Unknown switch. Switch: - For switch syntax, type "MSBuild /help". I have TFS 2010 on 2008 R2 server. Did look for type but no details. :/ – Hrvoje Kusulja Sep 07 '11 at 18:40
  • OK this is because of $(BuildDefinitionName) as part of string, so i have modified it to "$(Date:yyyyMMdd)$(Rev:.r)" and now it works, thank you very much !!! – Hrvoje Kusulja Sep 07 '11 at 18:52
  • That BuildNumber is confusing - I assumed it should contain just the number of each build in that day. But BuildNumber contains entire BuildName, and the actual daily build number is $(Rev). Oh, Microsoft, sometimes your logic is weird... – JustAMartin Jan 04 '13 at 19:23