How to distinguish between TFS assemblies and manual assemblies using macros in the Post build event

In the TFS post build script of the .proj file, I want to find out if the project is being built using the TFS built-in build or manually built build. Can anyone suggest me how to do this using macros in the Post Build event.

+6
source share
1 answer

Short answer: you can use the IsDesktopBuild MSBUILD property in your csproj file to distinguish between TFS and local build.

Long answer:

Developer or build team?

To distinguish between build environments, we must implement a mechanism that determines in which build environment. In other words, we need to know if we are doing a local build, performed by the developer or building commands on the build server. In fact, we should consider three different build environments:

Visual Studio Build - a build performed by the developer on his own development machine inside the Visual Studio environment

Team Build - assembly performed by TFS (manually or according to schedule) in the assembly.

Desktop Build - the build is explicitly done manually on the development workstation using the msbuild.exe tfsbuild.proj command.

A DesktopBuild and TeamBuild are very similar in nature, except that “DesktopBuild does not perform the GetLatest function from the source repository, there will be no” shortcut to the source tree and will not define a set of changes.

When using MSBUILD tasks (as we will use mainly in the following sections), one of the common ways to achieve this is to use the IsDesktopBuild and 'BuildingSolutionFile properties as conditions for testing in tasks. The IsDesktopBuild property is declared in Microsoft.TeamFoundationBuild.targets. The BuildingSolutionFile property is declared and automatically assigned by MSBUILD.

The following table lists the values ​​for each of these properties in each build environment.

Environment IsDesktopBuild BuildingSolutionFile Visual Studio Build (empty) (empty) Desktop Build true true Team Build false true 

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

We simply add the following element to all target files, where we need to distinguish between assembly on the development machine and assembly on the assembly server (in the first section).

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

Update: thanks @dbardakov. Starting VS 2012, we can use the property to find out if the build is happening in Visual Studio:

 BuildingInsideVisualStudio 

MSDN SOURCE - for BuildingInsideVisualStudio

SOURCE MSDN

+11
source

Source: https://habr.com/ru/post/974367/


All Articles