Dave Paquette

Caffeine Driven Development

Prairie Dev Con Wrap Up

March 4, 2015

I just returned from Prairie Dev Con (PrDC) in Winnipeg. As with every previous Prairie Dev Con, I was not disappointed. Every PrDC I have attended has been fantastic and yet each year it continues to get better.

My Favorite Session

I attended a number of sessions related to improving the performance of web applications. I learned something in every session, but Nik Molnar’s session on Full Stack Web Performance particularly stood out for me. I picked up countless web performance tips that I was able to apply to my current project as soon as I got back to work. Some of the tips he covered can be found at http://jankfree.org/.

My Sessions

I was fortunate enough to present two sessions. I have posted the slides on SlideShare for anyone who is interested.

The State of Entity Framework

Visual Studio 2013 with Link and Bower

Sessions I did not get to attend

There are two sessions that everyone was talking about and I was unable to attend because they were at the same time as my sessions. Luckily for me (and you), these sessions were recorded and are available on YouTube:

The Empathy Equation – Dave Mosher

The 5 Stages of Entrepreneurial Grief – Derick Bailey

Waiting for gulp tasks to finish in Visual Studio

February 23, 2015

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:

$start = $(Get-Date)
$rootPath = $args[0]
 
#Files to wait for
$bootstrapBundle = $rootPath + "Scripts\bootstrap-bundle.min.js"
$jqueryBundle = $rootPath + "Scripts\jquery-bundle.min.js"
$modernizer = $rootPath + "Scripts\modernizer-min.js"
$css = $rootPath + "Content\dist\css\app.min.css"
$glyphicons = $rootPath + "Content\dist\fonts\glyphicons-halflings-regular.*"
 
#Delay 2 seconds to ensure the gulp tasks were started (ie. Make sure we aren't testing for files before they were deleted and regenerated)
Start-Sleep -Seconds 2
while(!((Test-Path $bootstrapBundle) -and (Test-Path $jqueryBundle) -and (Test-Path $modernizer) -and (Test-Path $css) -and (Test-Path $glyphicons))) {
    Write-Output "Waiting for generated files"
    Start-Sleep -Seconds 2
    $elapsedTime = $(Get-Date) - $start
   #Wait a maximum of 60 seconds for the files to appear
    if ($elapsedTime.TotalSeconds -gt 60){
        Write-Error "Timed out while waiting for generated files"
        exit -2
    }
}
exit 0
 
$start = $(Get-Date)
$rootPath = $args[0]

#Files to wait for
$bootstrapBundle = $rootPath + "Scripts\bootstrap-bundle.min.js"
$jqueryBundle = $rootPath + "Scripts\jquery-bundle.min.js"
$modernizer = $rootPath + "Scripts\modernizer-min.js"
$css = $rootPath + "Content\dist\css\app.min.css"
$glyphicons = $rootPath + "Content\dist\fonts\glyphicons-halflings-regular.*"

#Delay 2 seconds to ensure the gulp tasks were started (ie. Make sure we aren't testing for files before they were deleted and regenerated)
Start-Sleep -Seconds 2
while(!((Test-Path $bootstrapBundle) -and (Test-Path $jqueryBundle) -and (Test-Path $modernizer) -and (Test-Path $css) -and (Test-Path $glyphicons))) {
    Write-Output "Waiting for generated files"
    Start-Sleep -Seconds 2
    $elapsedTime = $(Get-Date) - $start
   #Wait a maximum of 60 seconds for the files to appear
    if ($elapsedTime.TotalSeconds -gt 60){
        Write-Error "Timed out while waiting for generated files"
        exit -2
    }
}
exit 0
 

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.

 

image

Powershell -ExecutionPolicy bypass -File "$(ProjectDir)WaitForFiles.ps1" "$(ProjectDir)\"
Powershell -ExecutionPolicy bypass -File "$(ProjectDir)WaitForFiles.ps1" "$(ProjectDir)\"

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.