Geeks With Blogs
Blog Moved to Blog Moved to
When working on enterprise level applications and even smaller ones, I tend to automate everything for my builds as much as possible.  My recent experience with an enterprise SharePoint rollout is no different.  I'll walk through a basic scenario where I can deploy my web part library to my local instance through build events.
The prerequisite of this of course is that you have the templates installed.  If you do not, they can be found here:
Let's walk through a simple example of how you can automate the deployment.  First, launch Visual Studio 2003 and create a new Web Part Library project.  In this example, I will call my library ExampleWebPartLibrary.  This will create for you the following files:
*  Manifest.xml
*  WebPart1.dwp
*  WebPart1.cs
Sign the assembly by using the sn -k to create the strong name key and then place in the AssemblyInfo.cs.  Next, we will create a text file and place it in our project.  Right-click on the project and add new Text File.  Call this file MakeCabParams.txt.
The file must contain the following text:
.set DiskDirectoryTemplate=CDROM
.Set CompressionType=MSZIP
.Set UniqueFiles="OFF"
.Set Cabinet=on
.Set DiskDirectory1=.

If you notice in the above, we specify the name of our .cab file as  We also specify which files it includes, including the debug version of my dll, the dwp and manifest.xml.  If you need to add any additional files, just add more files after manifest.xml.
Now, let's take a look at the post-build event.  Go to Project Properties and then navigate to Build Events.  Click the elipsis next to the Post-build Event Command Line and enter the following text:
cd $(ProjectDir)
makecab /f MakeCabParams.TXT
"c:\program files\common files\microsoft shared\web server extensions\60\bin\stsadm.exe" -o addwppack -filename -globalinstall –force
As you note from the above text, we use the text file we created called MakeCabParams.TXT.  We also specified the name of the cab file to install.  After we do all of this, it is time to build the project.  Build the project and note the text in the output window. 
Here is what you should expect:
------ Build started: Project: ExampleWebPartLibrary, Configuration: Debug .NET ------

Preparing resources...
Updating references...
Performing main compilation...

Build complete -- 0 errors, 0 warnings
Building satellite assemblies...
Performing Post-Build Event...
Microsoft (R) Cabinet Maker - Version 5.2.3790.0
Copyright (c) Microsoft Corporation. All rights reserved..

Parsing directives
Parsing directives (MakeCabParams.TXT: 1 lines)
17,850 bytes in 4 files
Executing directives
  0.00% - ExampleWebPartLibrary.dll (1 of 3)
  0.00% - WebPart1.DWP (2 of 3)
  0.00% - Manifest.xml (3 of 3)
100.00% - Manifest.xml (3 of 3)
  0.00% [flushing current folder]
 94.43% [flushing current folder]
  4.09% [flushing current folder]
100.00% [flushing current folder]
Total files:               4
Bytes before:        17,850
Bytes after:          3,203
After/Before:            17.94% compression
Time:                     0.04 seconds ( 0 hr 0 min 0.04 sec)
Throughput:             435.79 Kb/second Deploying to http://mydevserver/.
Operation completed successfully.

---------------------- Done ----------------------

   Build: 1 succeeded, 0 failed, 0 skipped
If you look in the GAC, you should see the that there is indeed an entry should you browse to C:\Windows\Assembly. 
There is another way to do this without dealing with DWPs and such by using InstallAssemblies, which I have posted about before.  In order to utilize InstallAssemblies for your post-build event, simply change your Post-Build Event Text to the following:
"C:\Program Files\Web Part Toolkit\InstallAssemblies\InstallAssemblies.exe" /assembly:ExampleWebPartLibrary.dll
Of course it isn't the most elegant solution in the world because it pops up the UI during the middle of my build process and doesn't capture any of the information in the output window, which would be preferred.
Either way works really, but it is preferred to create the cabs for moving builds from environment to environment.
Posted on Thursday, June 1, 2006 4:25 PM Microsoft , SharePoint , .NET , Visual Studio | Back to top

Comments on this post: Automating SharePoint Deployment Through Post-Build Events

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Matthew Podwysocki | Powered by: