In a previous post, I outlined how to use Bower in Visual Studio 2013. While this code works for the typical developer workflow, a reader pointed out that errors were observed when attempting to publish to Azure using the Visual Studio publish dialog.
After further investigation, I was able to determine the reason for this error is due to the way Task Runner Explorer executes tasks. While we setup the binding so that our default Gulp tasks runs Before Build, this does not fully integrate into the Visual Studio build pipeline. The Gulp task is indeed triggered before Visual Studio starts to build the project, but Visual Studio does not wait for the task to complete before building the project. As a result, if your VS project is small enough, Visual Studio might think the build is completed before our Gulp task is completed. This is the reason for the Publish failing: Visual Studio was proceeding with publishing to Azure before all the required files were generated.
A Potential Workaround
Eventually, there will be better support for this in future versions of Task Runner Explorer. In the meantime, we need a simple workaround. One option is to run a script as a Post Build Event for my project to wait for all the generated files to exist. I did this as a simple PowerShell script file named WaitForFiles.ps1:
Now, execute this script in the Post Build event of the web project. You can set the post build event from the Build Events tab of the Project Properties page.
While this is not an ideal solution, it should fix the problem of Visual Studio attempting to publish your application before the required files have been generated by your Gulp tasks. In future versions of Visual Studio I would expect this integration to be a little cleaner.