Quick tip: Auto copy SharePoint 2013 .Net 4 DLL to GAC with VS2012

When working on complex SharePoint projects I often haver a number of projects, some of which produce DLL’s that are deployed to the GAC when the completed solution is deployed to SharePoint. Since life is short, I don’t want to be redeploying the solution every time I update one of these DLL’s. Instead I just want to copy the DLL to the GAC and maybe recycle an app pool.

While we wait eagerly for the SP2013 version of CKSDev, here’s a quick post-build script that’ll do the job:

  1. Select a project then Properties > Build Events.
  2. In the Post-build event command line box add the following:
if "$(ConfigurationName)"=="Debug" (
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\gacutil.exe" -i $(TargetPath)
"C:\Windows\System32\inetsrv\appcmd.exe" recycle apppool "19311de9d6b64338a982be8c9af45345"

Note: Change the app pool name to something appropriate to your project. If you’re DLL is being used in a front end process you probably want:

"C:\Windows\System32\inetsrv\appcmd.exe" recycle apppool "SharePoint – 80"

Now when you build your project in debug mode (i.e. on your dev box), you’ll see the following in the output window:

1>------ Build started: Project: MyCompany.MyWidget, Configuration: Debug Any CPU ------
1>  MyCompany.MyWidget -> C:\Code\SharePoint2013\MyCompany.MyWidget.dll
1>  Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.17929
1>  Copyright (c) Microsoft Corporation.  All rights reserved.
1>  Assembly successfully added to the cache
1>  "19311de9d6b64338a982be8c9af45345" successfully recycled
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

This entry was posted in CKSDev, SharePoint 2013, Tip. Bookmark the permalink.