« Setting up a draft save location for InfoPath web forms | Main | InfoPath - Using preceding:: XPath expression to hide repeating row label »
Wednesday
Apr062011

Adding a warm-up step to your SharePoint project deploy action

 

VS.NET 2010 allows a lot of awesome control over the exact steps that occurs when you deploy your project to your development environment.

image

Figure: VS.NET 2010 Deploy

 

When you are deploying farm solutions however, it does an IIS Reset, which means when VS.NET says it's done, and you go into your browser to test the site, it sits there for a few minutes warming up.  Sad smile

Fortunately, VS.NET is very extensible, and the community is awesome and has already added many useful extensions.

Grab CKS DEV

To fix this, first grab CKS extensions here: http://cksdev.codeplex.com/

 

SharePoint Project Properties | SharePoint

You can't edit any of the default configurations, so make your own and add the actions you want.

image

CKS provides a deployment step "Warm up SharePoint Site (CKSDev)" which will send a request to warm up the SharePoint site that the project deploys to.  (see #1 below)

image

The problem with the CKSDev warm-up step is that the action doesn't actually wait for the site to tell us it's ready, so VS.NET will say "Done", but when you open the browser, it's still not ready Sad smile

So we add another CKS step "Run PowerShell Script (CKSDev)".  See #2 above.

 

Using a PowerShell step to make sure it is REALLY READY

You then need to look at the properties of the project to see a new property under Deployment. 

Point that to a ps1 file in your project directory.

image

 

The contents of the ps1 file can be very simple, in 3 lines:

 

$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true
$Results = $WebClient.DownloadString("http://colt-sp2010/sites/Home/SitePages/default.aspx")

When you deploy now, it will run until the PowerShell step returns.  Smile

Activate Features:
  Activating feature 'Grid Feature' ...
Run Post-Deployment Command:
  Skipping deployment step because a post-deployment command is not specified.
Warm up SharePoint Site (CKSDev):
Run PowerShell Script (CKSDev):
  --Executing PowerShell Script #1 'D:\Temp\Grid\warmupsite.ps1'...
 
  --Script 'D:\Temp\Grid\warmupsite.ps1' successfully executed
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

Reader Comments (3)

You say "Point [the project property] to a ps1 file in your project directory" but your example uses an absolute path outside the project folder. Can this file name/path property use a project relative path? What to do if there are spaces in the file path? I tried a couple of ways:
- warm-up.ps1
- ..\..\warm-up.ps1 (assuming the path is relative to the bin\Debug folder)
- C:\Projects\solution - name\project - name\warm-up.ps1 (with spaces, no good)

but always got an error.

When I used an absolute path without spaces it worked fine:
- C:\Projects\soluti~1\projec~1\warm-up.ps1

Run PowerShell Script (CKSDev):
--Executing PowerShell Script #1 '..\..\warm-up.ps1'...
The term '..\..\warm-up.ps1' is not recognized as the name of a cmdlet, functio
n, script file, or operable program. Check the spelling of the name, or if a pa
th was included, verify that the path is correct and try again.
At line:1 char:18
+ ..\..\warm-up.ps1 <<<<
+ CategoryInfo : ObjectNotFound: (..\..\warm-up.ps1:String) [], C
ommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

December 28, 2011 | Unregistered CommenterJohnC

Check http://cksdev.codeplex.com/workitem/6251

Seems to imply the relative path issue has been resolved?

December 29, 2011 | Registered CommenterJohnLiu.NET

I had a quick look at the CKS code and it doesn't seem like they've added the issue regarding relative powershell paths. I haven't tested this in a real environment and can be wrong about this though.

December 29, 2011 | Registered CommenterJohnLiu.NET

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>