title: Pre-Build Target not running
body: <p>I created an MSBuild target to restore NPM packages in my ASP.NET Core app. I modeled it after Microsoft's own project template target for Node.js projects, though my project is not Node.js it only uses NPM packages for TypeScript defs.</p>
  
  <p>When my Azure DevOps pipeline builds it does not run my target unless I explicitly force it to with <em>-t:RestoreNode</em>. Why does my target trigger in Visual Studio but not in DevOps? Here is my target:</p>
  
  <pre><code>&lt;Target Name="RestoreNode" BeforeTargets="Build"&gt;
    &lt;!-- Ensure Node.js is installed --&gt;
    &lt;Exec Command="node --version" ContinueOnError="true"&gt;
      &lt;Output TaskParameter="ExitCode" PropertyName="ErrorCode" /&gt;
    &lt;/Exec&gt;
    &lt;Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." /&gt;
    &lt;Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." /&gt;
    &lt;Exec Command="npm install" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>Here is the pipeline:</p>
  
  <pre><code>trigger:
  - master
  
  pool:
    vmImage: 'windows-2019'
  
  variables:
    buildConfiguration: 'Release'
    runtimeConfiguration: 'win-x64'
  
  steps:
  - task: DotNetCoreCLI@2
    inputs:
      command: 'build'
      arguments: '-t:RestoreNode --configuration $(buildConfiguration) --runtime $(runtimeConfiguration)'
  
  - task: DotNetCoreCLI@2
    inputs:
      command: 'publish'
      publishWebProjects: true
      arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory) --runtime $(runtimeConfiguration)'
  
  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'drop'
      publishLocation: 'Container'
  </code></pre>