Answers: <p>I had the same problem and fixed it with this solution:</p>
  <ul>
  <li>for the pipeline yaml I added an additional param, could be any random name, I choose &quot;AzureBuild&quot; and set it to true:</li>
  </ul>
  <p><a href="https://i.sstatic.net/QKukf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QKukf.png" alt="enter image description here" /></a></p>
  <ul>
  <li>for the *.csproj file I added a Condition to Exec with that defined param in mind:</li>
  </ul>
  <p><a href="https://i.sstatic.net/oB3uB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/oB3uB.png" alt="enter image description here" /></a></p>
  <p>Now this post build events are only fired for local builds and not on Azure DevOps builds.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-05-10T08:55:05.600Z
Answers: took me a year, because stackExchange does not list this as my question for some reason, but it solved my problem, thanks !
Answers: Shubaka
Answers: CC BY-SA 4.0
Answers: 2021-07-01T05:12:37.330Z
Answers: 2021-07-01T05:12:37.330Z
Answers: Ziagl
Body: <p>I have built a simple pipeline to build my solution triggered by commits to the master branch using the Azure DevOps Pipelines.
  I have a problem with the post build copy commands failing and returning errors</p>
  <p><strong>my post build copy command:</strong></p>
  <pre><code>copy /Y &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(MY_PATH)$(TargetFileName)&quot;
  </code></pre>
  <p><strong>I get the following errors:</strong></p>
  <pre><code>PostBuildEvent:
    copy /Y &quot;D:\a\1\s\{some_path\file.dll}&quot; &quot;D:\a\1\s\BuildBin\{file.dll}&quot;    
  The system cannot find the path specified.
                0 file(s) copied.
  </code></pre>
  <p>the <code>MY_PATH</code> environmental variable is defined in the pipeline variables and using a &quot;CmdLine&quot; <code>echo %MY_PATH%</code> in the .yaml it echos the proper path in the console:</p>
  <pre><code>    Starting: CmdLine
  ==============================================================================
  Task         : Command line
  Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
  Version      : 2.177.3
  Author       : Microsoft Corporation
  Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
  ==============================================================================
  Generating script.
  Script contents:
  echo %MY_PATH%
  ========================== Starting Command Output ===========================
  &quot;C:\windows\system32\cmd.exe&quot; /D /E:ON /V:OFF /S /C &quot;CALL &quot;D:\a\_temp\1db7603c-e3c0-4e32-924f-c5b1fc2cf96e.cmd&quot;&quot;
  D:\a\1\s\BuildBin\
  Finishing: CmdLine
  </code></pre>
  <p>I have defined the <code>MY_PATH</code> to be <code>D:\a\1\s\BuildBin\</code> as I witnessed that this is the solution folder,
  the paths in the error are correct.</p>
  <p>Also I have tried running a script to create the BuildBin folder as I thought the folder does not exists but its not the reason as I run the following in the .yaml:</p>
  <pre><code>steps:
  - script: echo mkdir D:\a\1\s\BuildBin
  </code></pre>
  <p>I cant find any info on the topic any where, just <a href="https://stackoverflow.com/questions/64018782/azure-pipelines-post-build-event-copy-command-failure">this StackOverflow question</a> and it was not helpful.</p>
  <p>I'm running the job in Windows Windows Server 2019 environment.
  <strong>Needless to say the solution builds on my pc with no problems, it also builds fine in the pipeline, its just the copy that fails.</strong></p>
  
Tags: <azure-pipelines>
Title: Azure DevOps build pipeline error on copy in post build event
UserDisplayName: Shubaka
ThreadText: # Azure DevOps build pipeline error on copy in post build event
  
  (Asked by: username_0 on 2020-11-08)
  
  I have built a simple pipeline to build my solution triggered by commits to the master branch using the Azure DevOps Pipelines.
  I have a problem with the post build copy commands failing and returning errors
  
  **my post build copy command:**
  
  ```
  copy /Y "$(TargetDir)$(TargetFileName)" "$(MY_PATH)$(TargetFileName)"
  
  ```
  
  **I get the following errors:**
  
  ```
  PostBuildEvent:
    copy /Y "D:\a\1\s\{some_path\file.dll}" "D:\a\1\s\BuildBin\{file.dll}"    
  The system cannot find the path specified.
                0 file(s) copied.
  
  ```
  
  the `MY_PATH` environmental variable is defined in the pipeline variables and using a "CmdLine" `echo %MY_PATH%` in the .yaml it echos the proper path in the console:
  
  ```
      Starting: CmdLine
  ==============================================================================
  Task         : Command line
  Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
  Version      : 2.177.3
  Author       : Microsoft Corporation
  Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
  ==============================================================================
  Generating script.
  Script contents:
  echo %MY_PATH%
  ========================== Starting Command Output ===========================
  "C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\1db7603c-e3c0-4e32-924f-c5b1fc2cf96e.cmd""
  D:\a\1\s\BuildBin\
  Finishing: CmdLine
  
  ```
  
  I have defined the `MY_PATH` to be `D:\a\1\s\BuildBin\` as I witnessed that this is the solution folder,
  the paths in the error are correct.
  
  Also I have tried running a script to create the BuildBin folder as I thought the folder does not exists but its not the reason as I run the following in the .yaml:
  
  ```
  steps:
  - script: echo mkdir D:\a\1\s\BuildBin
  
  ```
  
  I cant find any info on the topic any where, just [this StackOverflow question](https://stackoverflow.com/questions/64018782/azure-pipelines-post-build-event-copy-command-failure) and it was not helpful.
  
  I'm running the job in Windows Windows Server 2019 environment.
  **Needless to say the solution builds on my pc with no problems, it also builds fine in the pipeline, its just the copy that fails.**
  
  **Tags:** azure-pipelines
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-07-01. Score: 2 | Accepted answer
  
  I had the same problem and fixed it with this solution:
  
  * for the pipeline yaml I added an additional param, could be any random name, I choose "AzureBuild" and set it to true:
  
  [![enter image description here](https://i.sstatic.net/QKukf.png)](https://i.sstatic.net/QKukf.png)
  
  * for the \*.csproj file I added a Condition to Exec with that defined param in mind:
  
  [![enter image description here](https://i.sstatic.net/oB3uB.png)](https://i.sstatic.net/oB3uB.png)
  
  Now this post build events are only fired for local builds and not on Azure DevOps builds.
  
  > **Comments:**
  > **username_0**: took me a year, because stackExchange does not list this as my question for some reason, but it solved my problem, thanks !  
  
  ---
  
  