Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect TFS Build vs. Visual Studio build

Is it possible to detect whether or not the current build is executing from Visual Studio rather than an automated build with TFS without creating a separate solution configuration? I'm wondering if I can exclude certain Post Build Events if the build is running on TFS 2013, but if possible I would like to avoid a whole separate configuration.

like image 209
Malaise Avatar asked Jun 01 '15 17:06

Malaise


People also ask

What is the difference between MSBuild and Visual Studio build?

Visual Studio determines the build order and calls into MSBuild separately (as needed), all completely under Visual Studio's control. Another difference arises when MSBuild is invoked with a solution file, MSBuild parses the solution file, creates a standard XML input file, evaluates it, and executes it as a project.

What is a TFS build?

Team Foundation Server (TFS) is an ALM product from Microsoft which provides the capabilities for an end-to-end development and testing using Work Item Management, Project Planning (Waterfall or Scrum), Version Control, Build/Release (Deploy) and Testing capabilities.

Is TFS a build server?

This topic describes how to prepare a Team Foundation Server (TFS) build server to build and deploy your solutions using Team Build and the Internet Information Services (IIS) Web Deployment Tool (Web Deploy).


2 Answers

You do not need to edit the CSProj file: just use CMD.EXE syntax in Visual Studio Post-Build events

You can test if running inside Visual Studio

IF "$(BuildingInsideVisualStudio)"=="true" (
  …
)

or inside TFS Build (2013 or later)

IF "$(TF_BUILD)"=="True" (
  …
)

See the discussion a TFS 2010 Build Automation and post-build event and Team Foundation Build environment variables.

like image 134
Giulio Vian Avatar answered Sep 18 '22 16:09

Giulio Vian


It is possible, and I finally found out how:

  1. Unload the project in question, that has a PostBuildEvent defined.
  2. Edit the .csproj file.
  3. Locate the PostBuildEvent XML element, and add a Condition attribute like the following:

    <PostBuildEvent Condition="'$(BuildingInsideVisualStudio)' == 'true'">

At this point the PostBuildEvent will only execute when built with Visual Studio.

This answer and other answers to that question were helpful.

This particular property is briefly mentioned on this MSDN page as well.

like image 26
Malaise Avatar answered Sep 19 '22 16:09

Malaise