Random Thoughts of a Scatterbrain.
 Thursday, April 24, 2008

Automating Remote GAC Installs On Build

4/24/2008 4:42:15 PM (Eastern Daylight Time, UTC-04:00)

When working with SharePoint, you'll find yourself working with the GAC quite often during development.

If you've seen the light and you're working with SharePoint on a VM, one tricky problem is how to update the GAC using a post-build event.  The following is a little script that I use:

::----------------------- GAC binaries code ------------------------
:: Check if the share is available on the server
IF EXIST "\\server-name\temp" GOTO COPYFILES
GOTO SHOWNOTICE

:: Copy file to the server
:COPYFILES
ECHO Found \\server-name\temp; proceeding to copy files...

SET SN=\\server-name\temp

:: Copy the binary
XCOPY "$(TargetPath)" "%SN%" /Y /I

:: Use PsExec to execute gacutil
PATH=$(SolutionDir)Tools;%windir%\Microsoft.Net\Framework\v2.0.50727;%programfiles%\Microsoft SDKs\Windows\v6.0\Bin;%path%

psexec \\server-name -u Administrator -p password -w "c:\temp" gacutil.exe /i "$(TargetFileName)" /f

GOTO END

:SHOWNOTICE
ECHO Your VM image is not sharing the directory "c:\temp"
GOTO END

:END
ECHO Completed

The batch script makes use of Sysinternal's PsExec.  I've included the binary executable in my solution tree under the directory "Tools".

The script only has one assumption: the VM (or remote machine, really) is sharing the c:\temp directory (okay, and that the path to gacutil.exe has been added to the remote machine's PATH environment variable).  Here's a breakdown of the logic:

  1. The first step is to check if the directory exists and can be reached.  If not, we go to the end and show a notice about sharing the directory.
  2. If the directory is shared, the output dll from the build is copied to the shared directory using plain old XCOPY.
  3. Once it's copied over, we use PsExec to execute gacutil on the VM (or remote machine).  The -w argument specifies the working directory on the remote machine.

Enjoy!

Name
E-mail
Home page

Comment (HTML not allowed)  
Enter the code shown (prevents robots):

RSS 2.0 Atom 1.0 CDF