Tuesday, May 20, 2008

PowerShell for Flexible Iterative SharePoint-based Development


This post by David Mann is a good resource for 3rd-party and MS tools to help with SharePoint-based software development:

Using Tools to make SharePoint Development Easier

While we here at the SharePoint Solutions Software Division certainly use some of the tools mentioned in David’s post, I guess maybe our development requirements are a bit "heavier" than the typical IT project since we're developing packaged products for commercial redistribution. We need the fined-grained control of a flexible, highly re-usable tool-chain.

Our developers use PowerShell extensively for various iterative "build and deploy" scenarios. For example, here's the usage menu from a PowerShell script called Deploy-ExCM which we use while working on our ExCM product:

----------

PS C:\usr\src\devteam\ExtranetCollaborationManager2009\Mainline\Dependencies> .\deploy-excm -u

Deploy-ExCM
Build and deploy utility script for Extranet Collaboration Manager

Deploy-ExCM usage information.
Arguments:
-i Recycle IIS application pool
-a Deploy artifacts (xcopy)
-g Deploy assemblies to GAC
-b Build solution (devenv)
-fui Uninstall / Install Features
-fda Deactivate / Activate Features
-bcl Update BCL assemblies to GAC
-testweb Delete and recreate test web
-wsp Build WSP package (makecab)
-light Light deployment -a
-heavy Heavy deployment -b -a -g -bcl -i

Examples:
deploy-excm -a -b -i -g
deploy-excm -b -g
deploy-excm -a -i -g -testweb -fui

----------


In our development environments, each developer using this script has a few environmental variables set in his/her Microsoft.PowerShell_profile.ps1 profile:

----------

#
# User-specific settings
#
write-output "`nSetting environment for SharePoint Solutions development.`n"
$WorkspaceRootDir = "C:\usr\src\devteam"
$PowerShellLibDir = "${WorkspaceRootDir}\DeveloperCenter\PowerShell"

# ExCM
$VBL_ExCM = "Mainline"
$BuildConfig_ExCM = "Debug"
$AppPool_ExCM = "SharePoint - 8081"
$AppRoot_ExCM = "C:\inetpub\wwwroot\wss\VirtualDirectories\8082"
$SiteUrl_ExCM = "http://devapp08:8082"
$WebUrl_ExCM = "http://devapp08:8082/downloadstest"

---------


The wide range of flags and parameters for Deploy-Excm make it a flexible and convenient tool for use while we work on the various types of artifacts involved in a SharePoint solution package. For the most common iterative build scenarios, I call the utility directly from the Visual Studio Tools menu as an External Tool. The three permutations I've added there are:

Deploy-ExCM (iterative) - this calls deploy-excm -a -i -g
Deploy-ExCM (heavy) - this calls deploy-excm -a -i -g -testweb -fui
Deploy-ExCM (makecab) - this calls deploy-excm -wsp

For your reference, here are the PowerShell scripts we're using.

1. Profile - contains developer-specific variables, pathing modifications, and PowerShell translation of vsvars32.bat:
http://www.codekeep.net/snippets/9ba5c3c9-87ea-44f2-81cd-7466f982caaf.aspx

2. Shared Functions - re-usable functions
http://www.codekeep.net/snippets/c3069a2f-3027-496c-8d0a-94e1a0894cfb.aspx

3. Deploy-* - product/project specific calls, command-line parsing:
http://www.codekeep.net/snippets/8071237c-fb1f-4426-96bb-1b4b75f96631.aspx

We try to have a "Deploy-*" script for each major product/project we work on. By sourcing PowerShell include files, much of the internal functions are re-used across scripts. If anyone has questions, feedback, suggestions or would just like to discuss further, please leave your comments and we'll start a dialog.
Post a Comment