How can one determine if a csproj is being run on a TFS build agent?

When calling MSBuild from the command line, you can pass/overwrite properties like this:

# Simulate Visual Studio build
. msbuild.exe Project.csproj /p:BuildingInsideVisualStudio=true [...]

# Custom property
. msbuild.exe Project.csproj /p:MyCustomProperty=true [...]

Is use these to check them in my post/afterbuild events.


I have TFS2012 and use this:

<IsTfsServerBuild Condition=" '$(IsTfsServerBuild)' == '' ">false</IsTfsServerBuild>
<IsTfsServerBuild Condition=" '$(BuildingInsideVisualStudio)' != 'true' AND '$(BuildUri)' != '' ">true</IsTfsServerBuild>

You have a few options:

  1. '$(BuildingInsideVisualStudio)' != ''
  2. '$(TeamBuildConstants)' != '' (supported in team Build 2008)
  3. '$(IsDesktopBuild)' == 'false'
  4. '$(tf_build)' != '' (supported in recent versions of Azure Pipelines)

You can check either one to detect the context the task has been executed in. If both don't evaluate then MsBuild has been called from the commandline or some other process.