开发者

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

开发者 https://www.devze.com 2023-04-03 08:50 出处:网络
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:

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消