My first post in 2009. Took only 2 months into the year. Sigh! There goes my resolution. On the positive side, it is a technical post. Been a while since I posted one of these.

Anyways, let’s get to the point.

So in the current project I’m working on, I build SharePoint web parts. A lot of them. As with typical SharePoint projects, the web parts need to be deployed to the GAC/assembly. before they can be added to the pages.

The problem with this as you can imagine, is that every change no matter how small or big it is, needs to be built and the assembly copied to the GAC (C:\Windows\assembly). If you are using the WSPBuilder Visual Studio plugin, this is probably a bit less cumbersome than going to the location of the DLL and manually copying it and pasting it in the assembly folder, you know, using good old Windows Explorer.

This is great if you are big fan of the mouse. Just 4 clicks/gestures. One for the build. And 3 for the GAC deployment – Right click on the project, Click on WSPBuilder, Select Copy to GAC.

But for people like me, that prefer keyboard short cuts over mouse clicks, here’s how we can make this much faster – Map custom short cut keys to do the build and deploy.

You may already know that Ctrl + Shift + B builds the project. But it builds not just the current project but every other project related to it (and may be even the independent ones too if I’m right).

Now that is still 3 keys. Let’s see if we can bring it down to 2 keys.

Here we go.

  1. Click on Tools – Customize in Visual studio as shown below. 

Click on Tools Then Click on Customize

2. Click on Keyboard

Click on Keyboard

3.  We need to find “Build.BuildSelection” command. So start typing that in the “Show commands containing” textbox. It’s autocomplete as you can see below. So just select the item as soon as it shows up.

Type Build.BuildSolution in Show Commands textbox

4. After you select it from the list, move your cursor to the “Press shortcut keys” textbox below and press the short cut keys. I chose Shift + F1 since I just have to use my left hand fingers and the keys aren’t too far apart.

Note that you CANNOT type your shortcut. You HAVE to press the keys on your keyboard as the text above the textbox says.

Select Build.BuildSolution from the list

5. After you select your short cut, the “Assign” button gets enabled as shown below. Click on that to assign the short cut to “Build.BuildSelection”. “Assign” button now becomes “Remove”. It took it. Good.

Assign Short Cut

6. Now click OK.

Click OK

7. Test the short cut now. Open up a file in a project and use your short cut. If everything worked ok, the project that file belonged to, would have been built. Just that project.

8. Wash. Rinse. Repeat. Do the same for “Copy To GAC” feature.

9. Look for “copytogac” in the commands text and you may notice that once you select the command as shown below, there already might exist a short cut for it. In this case it is Ctrl + Shift + Alt + B.

I don’t know about you but that is lot of keys to press for a simple command. It is ok though. You can leave it alone and map yet another short cut to the same command.

Type CopyToGac in the commands textbox

I chose Shift + F2. 

Assign ShortCut to GAC

10. Click Assign and then OK. And all done! Now we can easily build and deploy the currrent web part/dll to the GAC with the press of just 2 keys per command.

Shift + F1 to build. Shift + F2 to deploy to GAC.

I suppose it must save some amount of time in the long term. Enjoy! :)

If you have been in a situation where things are in a big hairy mess, you probably would follow the process of elimination to ensure you are not chasing the wrong items down the rabbit hole.

Now consider you are working with SharePoint and you are in a tight spot as mentioned above. You probably want to ensure that WSS/MOSS has been configured properly and that the problem is not with the webpart you are working on, for example.

Here’s a quick and easy way of writing a “hello world” webpart that doesn’t involve features and layouts and WSPs and stsadm commands and etc.

1. Open up Visual Studio 2008 and create a new class library project (name it something unique, for example, DingDongBellWebPart) and add the following code in Class1.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web.UI.WebControls.WebParts;

namespace DingDongBellWebPart

{

public class Class1 : WebPart

{

protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)

{

writer.Write(“DingDongBell test”);

base.Render(writer);

}

}

}

}

2. Check the “Sign the assembly” checkbox in Project properties “Signing” tab as shown below

Project properties

(Click on image above for better resolution)

3. Under “Choose a strong name key file” dropdownlist, select “New”.

4. Uncheck “Protect my key file with a password” as shown below

Create Strong Name Key

5. Give it a name and click OK.

6. Build the project.

7. Drag the project’s dll from the bin folder and drop it in C:\Windows\assembly folder. This registers the DLL in the GAC.

8. Replace the values for the attributes where necessary in the line below and add this line in the <SafeControls> section in the web.config file of the website you are trying to deploy this webpart to. (You can even try the SharePoint’s central admin’s web.config file. should work.)

<SafeControl Assembly=”DingDongBellWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1af588c27b5f26e0″ Namespace=”DingDongBellWebPart” TypeName=”*” Safe=”True” />

**NOTE**: Don’t forget to replace the PublicKeyToken above. There are multiple ways to fetch the PublicKeyToken of your DLL. Here’s one way. Go to C:\Windows\assembly and right click on your assembly and click properties as shown below.

Webpart properties

9. Visit the following URL – http://insert_your_website_url_here/_layouts/NewDwp.aspx [Of course replace "insert_your_website_url_here" with your value]

10. It should show up in that list as shown below. (I know….it says GirishWebpart.Class1 in the screenshot below instead of DingDongBellWebpart.Class1. May be it is because I figured GirishWebpart was a much better name than the ridiculous-sounding DingDongBellWebpart.)

Webpart properties

(Click on image above for better resolution)

11. If it doesn’t work, reset IIS. And try again. Should work.

12. Enjoy.

Alright Microsoft. You win. I have officially started working with Sharepoint now. I’m now one of the thousands of .Net developers that have been slowly but steadily and methodically, sucked into dark side of the “portal” world. A bunch of us in my company were hoping and praying that we don’t get placed on a project that would force us to learn this technology especially because of the horror stories we’ve heard. When someone like Rob tells you that sharepoint is the shittiest piece of software he’s ever worked on, that is saying something.

Anyways, enough of bitching. Every Sharepoint developer that i knew, installed VMWare on their machines that ran Windows 2003, SQL Server 2005 and VS 2005/2008 and used that as their development environment. Why? Because WSS 3.0 or MOSS 2007 runs only on server operating systems. Brilliant! Let me get this straight. We are supposed to build applications that would run on “portal” software that are hosted on servers, and so we are supposed to do our development on server operating systems? Of course! Makes perfect sense! Yay Microsoft!

I don’t know man…i just didn’t want to load yet another software on my box and do all the configuration. Luckily for me, Bamboo Solutions had figured out a way to get MOSS 2007 to run on Vista/XP operating systems. As always, i started off my learning process by opening up a brand new word document and taking screenshots of each and everything i did, right from scratch. That includes pictures of installation wizards, “This program has performed an illegal operation” errors (sugar coated for Vista), dashboards, Visual Studio IDE, etc.

The end result of all this pain is a document that has some blurry images but decent content on how to write a “Hello world” web part and successfully deploying it to a sharepoint portal, all starting from scratch. This tutorial would make more sense if you are a .Net developer and have been doing custom application development for a while. It is meant for someone that has no idea where to begin, in their attempt to learn Sharepoint. So if you feel some of the screenshots in the document insult your intelligence, just remember that not all people are as smart as you, wise guy.

Here’s the doc in PDF – How to get MOSS 2007 development environment setup in Vista.pdf

Enjoy!