如何在后期构建事件中使用宏来区分TFS构建和手动构建 [英] How to differentiate TFS Builds and manual builds using macros in Post build event

查看:67
本文介绍了如何在后期构建事件中使用宏来区分TFS构建和手动构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.proj文件的TFS后生成脚本中,我想查找项目生成是通过TFS触发生成还是手动触发生成进行的.有人可以建议我如何使用Post Build事件中的宏来执行此操作.

In TFS post build script of a .proj file I want to find whether the project build is happening through TFS triggered build or manually triggered build. Can someone suggest me how to do this using macros in Post Build event.

推荐答案

简短的答案:您可以使用csproj文件中的IsDesktopBuild MSBUILD属性来区分TFS和本地版本.

Short answer: you can make use of the IsDesktopBuild MSBUILD property within your csproj file to differentiate between TFS and local build.

长答案:

开发人员还是团队建设?

Developer or Team Build?

为区分构建环境,我们必须实现一种机制,该机制可检测在哪个环境中执行构建.换句话说,我们需要知道是运行由开发人员执行的本地构建,还是运行在构建服务器上的团队构建.实际上,我们需要考虑3种不同的构建环境:

To differentiate the build environments we have to implement a mechanism that detects in which environment the build is being executed. In other words, we need to know if we running a local build that is executed by the developer or a team build running on the build server. In fact, there are 3 different build environments we need to consider:

· Visual Studio构建 –由开发人员在Visual Studio IDE中自己的开发计算机上执行的构建

· Visual Studio Build – a build executed by a developer, on their own development machine inside the Visual Studio IDE

·团队构建 –由TFS在该构建上执行的构建(手动或计划).

· Team Build – a build executed by TFS (manually or scheduled), on the build.

·台式机构建 –使用命令"msbuild.exe tfsbuild.proj"在开发工作站上手动明确执行的构建.

· Desktop Build – a build explicitly executed manually, on the development workstation using the command 'msbuild.exe tfsbuild.proj'.

'DesktopBuild'和'TeamBuild'本质上非常相似,不同之处在于'DesktopBuild'不执行源存储库中的'GetLatest'功能,不会'标记'源树,也不会确定更改集.

A ‘DesktopBuild’ and a ‘TeamBuild’ are very similar in nature except that ‘DesktopBuild’ does not perform a ‘GetLatest’ function from source repository, will not ‘Label’ the source tree and will not determine the change set.

在使用MSBUILD任务时(我们将在以下各节中主要使用),实现此目标的一种常用方法是使用``IsDesktopBuild''和``BuildingSolutionFile''属性作为在任务中进行测试的条件.``IsDesktopBuild''属性为在"Microsoft.TeamFoundationBuild.targets"中声明.MSBUILD自动声明和分配了"BuildingSolutionFile"属性.

When using MSBUILD tasks (as we will use primarily in following sections), one common way to achieve this is to use the ‘IsDesktopBuild’ and ‘BuildingSolutionFile’ properties as conditions to test in the tasks.The ‘IsDesktopBuild’ property is declared in the ‘Microsoft.TeamFoundationBuild.targets’. The ‘BuildingSolutionFile’ property is declared and assigned automatically by MSBUILD.

下表列出了每个构建环境中每个属性的值.

The following table lists the values of each of these properties in each of the build environments.

Environment                    IsDesktopBuild                BuildingSolutionFile

Visual Studio Build               (empty)                         (empty)
Desktop Build                       true                            true
Team Build                         false                            true

使用"IsDesktopBuild"属性的一个警告是,默认情况下,没有在许多目标文件中定义该属性.此属性在Visual Studio构建中将具有空"值,因此我们将其初始化为默认值"true".因此,我们需要在将要测试它的所有MSBUILD目标文件中明确定义它.

One caveat with using the ‘IsDesktopBuild’ property is that it is not defined in many target files by default. This property will have an ‘empty’ value in a Visual Studio build, so we initialize it to a value of ‘true’ as the default value. Therefore we need to be explicitly define it in all MSBUILD target files where it will be tested.

我们只需在所有目标文件中添加以下元素,就需要在开发机器上的构建和构建服务器上的构建之间进行区分(在第一部分中).

We simply add the following element to all target files where we need to differentiate between a build on the development machine and a build on the build server (within the first section).

<IsDesktopBuild Condition="'$(IsDesktopBuild)' == ''">true</IsDesktopBuild>

更新:谢谢@dbardakov.从VS 2012开始,我们可以使用该属性来查找是否在Visual Studio中进行构建:

Update: thank you @dbardakov. Starting VS 2012 we can use the property to find if the build is happening within Visual Studio:

BuildingInsideVisualStudio

MSDN源-用于BuildingInsideVisualStudio

MSDN来源

这篇关于如何在后期构建事件中使用宏来区分TFS构建和手动构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆