Malaise
Malaise

Reputation: 711

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.

Upvotes: 5

Views: 2191

Answers (2)

Giulio Vian
Giulio Vian

Reputation: 8343

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.

Upvotes: 8

Malaise
Malaise

Reputation: 711

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.

Upvotes: 3

Related Questions