title: Visual Studio: Run a post build event in the background
body: <p>I have a powershell script that I want to run when the post-build event is triggered in Visual Studio.  However, it is important that the script runs in the background and does not pause the build process while it is running.  The other requirement is that I must be able to pass in the project directory with spaces in the directory name.</p>
  
  <p>I have been having trouble getting both to happen at the same time.  After much trial and error, I have found a complex solution to running a powershell script in the background, but it doesn't work with spaces in the directory name. Here is what I am currently doing, but I am quite open to something completely different as this seems overly complicated:</p>
  
  <p>In the post-build event in Visual Studio:</p>
  
  <pre><code>powershell -ExecutionPolicy Unrestricted start-process " $(ProjectDir)scripts\post-build.cmd" -ArgumentList $(TargetDir),$(ConfigurationName),$(ProjectDir)
  </code></pre>
  
  <p>And here is the post-build.cmd:</p>
  
  <pre><code>START /B CMD /C CALL "Powershell.exe" -ExecutionPolicy Unrestricted -file %3scripts\post-build.ps1 %1 %2 %3
  </code></pre>
  
  <p>I have tried just adding quotes around the arguments, but I keep getting various errors (i.e. missing terminator '"') from Powershell when I do so.</p>
  
  <p>Please forgive my ignorance, I am new to Powershell and Visual Studio.</p>