Prevent post build event in VSTS

2019-08-28 00:21发布

问题:

For development purposes my team has a post build event defined to pack and publish nuget packages locally. This step is not necessary during the build in VSTS because we have a step defined for that during the building to pack and ship the nuget packages to a different server, whithout symbols. Right now this step is executed in any build we run. How to prevent that only in the build server?

回答1:

You're going to have to dig into MSBuild for this. You need to add a condition to check for one of the environment variables that's set when running in the context of a build, and only run if that environment variable is blank.

For example,

  <PropertyGroup>
    <PostBuildEvent Condition=" '$(BUILD_SOURCESDIRECTORY)' == '' ">echo Hello World</PostBuildEvent>
  </PropertyGroup>

BUILD_SOURCESDIRECTORY is an environment variable that's populated when running in the context of a build, but isn't populated normally on a developer's desktop. Thus, echo Hello World will only run when that value is blank.