本文介绍了如何使用TFS服务器在.proj(MSBuild)中获取BuildNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将TFS 2010与VS 2010一起用于PHP Web项目.实际上,我们没有任何.proj或.sln文件,因此我自己制作了构建文件,它看起来像这样:

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>

我已在VS中的构建定义中将构建号配置为"$(BuildDefinitionName)_ $(Date:yyyyMMdd)$(Rev:.r)",并且网络路径上的放置文件夹已正确创建.

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.

问题是$(BuildNumber)或$(TeamProject)或$(BuildProperties)为空.而且似乎"My Afterbuild"从未执行.

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?

推荐答案

要运行AfterBuild目标:

<DefaultTargets="AfterBuild" />

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

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

对我来说,不清楚为什么要在Build目标之前执行Zip目标?

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

您必须通过将BuildNumber手动添加到MSBuild命令行来更新模板文件defaultTemplate.XAML,因此命令行类似于:

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)]" />

请参阅有关此技巧的原始文章: TFS2010 – $(BuildNumber)在哪里?

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

这篇关于如何使用TFS服务器在.proj(MSBuild)中获取BuildNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 09:15