in

Platinum Bay

Peace, Love, Team System, and Community

This Blog

Syndication


.NETicated

Visual Studio Build Events for SharePoint Developers

One of the extremely useful, yet under-utilized features of Visual Studio are the project build events. Build events are commands you can run before and/or after a project build. You can further specify that they run after a successful build or any build. Any command that can be run from the command line can be used as part of a build event. These include:

  • sn – strong name utility
  • copy and xcopy
  • makecab
  • conditional statements

You could even run ipconfig or ping if you wanted to. To open up the build events page, go to your project's property pages, and:

C# – Choose the Build Events tab.

VB – Choose the Compile tab, scroll to the bottom and click the "Build Events…" button.

Bang on the money, you say. Exactly, I say. But you ask, 'So I want to copy my compiled assemblies to the 12 hive, how do I know where my project assemblies are?' Ah, excellent question. A smart one aren't you? (If you're confused, rest assured that this sounded much better in my head in British English. Cheers.) But back on point, if you open up the build event dialog, and click on the Macros button, you will be presented with token variables for project and solution locations, extensions, and much more. Here are the macros available, along with values for a test throwaway project:

These macros make it incredibly easy to build custom event scripts. Here are some common build event scripts I use with SharePoint projects:

MAKECAB

Runs the makecab utility for DDF files.

cd "$(ProjectDir)"
"C:\Source\Utilities\MAKECAB.EXE" /f "WSP.ddf"

Recycle the Application Pool:

%25systemroot%25\system32\iisapp.vbs /a "AppPoolName" /r

Copy file to the 12 hive:

cd "$(ProjectDir)"
"TEMPLATE" "%25CommonProgramFiles%25\Microsoft Shared\web server extensions\12\TEMPLATE\" /ys

Create a deployment directory:

I use this command to take a bunch of SharePoint projects, and copy the outputs to a single directory.

copy "$(ProjectDir)bin\deploy\" "$(SolutionDir)deploy\"

Register an assembly in the GAC:

@SET gacutil = "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\gacutil.exe"
%gacutil% /iF MyAssembly.dll

Conditional Statements

The question of whether conditional statements were possible was posed to me at a local user group I presented at. The answer is yes, sort of.

Here's an example showing how to use the macros to evaluate the build type:

if $(ConfigurationName)==Release goto Release
if $(ConfigurationName)==Debug goto Debug

:Release
REM do something
goto End

:Debug
REM do something
goto End

:End

Build events provide a wonderful way to reduce or eliminate a lot of the manual steps in building, deploying and testing SharePoint solutions. Have fun!

Comments

November 23, 2007 10:10 PM

Link Listing - November 23, 2007

 

November 23, 2007 10:10 PM

Sharepoint Visual Studio Build Events for SharePoint Developers [Via: Steve ] Visual Studio External...

 

October 7, 2008 2:39 AM

good review

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews is a Team System MVP and INETA Speaker, and has been working as a developer for more than 9 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. Steve is also an MCP, ICSOO, Speaker Liaison for the Philly .NET User Group, and community fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.