Determining if you’re running on the build server with MSBuild – Easy way

When you're customizing MSBuild in building a visual studio project, it often becomes important to determine if the build is running on the build server or your development environment.

This information can change the way you set up path variables and other Conditional tasks.I've found many different answers online.

It seems like they all only worked under certain conditions, so none of them were guaranteed to be consistent.So here's the simplest way I've found that has not failed me yet.

  <PropertyGroup>
    <!-- Determine if the current build is running on the build server -->
    <IsBuildServer>false</IsBuildServer>
    <IsBuildServer Condition="'$(BuildUri)' != ''">true</IsBuildServer>
  </PropertyGroup>
 


Shahzad Qureshi is a Software Engineer and Consultant in Salt Lake City, Utah, USA

His certifications include:

Microsoft Certified System Engineer
3CX Certified Partner
Global Information Assurance Certification – Secure Software Programmer – .NET

He is the owner of Utah VoIP Store at www.UtahVoIPStore.com and SWS Development at www.swsdev.com and publishes windows apps under the name Blue Voice.