!! Absolutely no warranties, use at your own risk !!


I started to try the whole thing, because if you want to install the Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions on a Vista Machine it will fail:




So it is not possible to install the extension on a developer workstation. The official way to develop MOSS 2007 WebParts is to work on a Windows Server 2003 with at least WSS 3.0 installed or to use a similar VPC environment. In the VPC case this means you need to have at least 2 GB of memory available, in order to spend 1 – 1.5 GB for the Sharepoint Server VPC.


Setting up the Server or VPC Environment:

1. First of all you need a Windows Server 2003 machine or VPC, where MOSS 2007 is installed.
2. Install Visual Studio 2005 on the machine or VPC.
3. Install all Updates from Windows Update including Service Pack 1 for Team Suite or Service Pack 1 for Express Editions. If you run on Vista install the Service Pack 1 Update for Vista
4. Install WSS SDK, Office Server SDK and Visual Studio 2005 Extensions.


Setting up the Developer Workstation:


1. You need a Windows XP SP2 or Windows Vista Machine with Visual Studio 2005 installed.
2. Install all Updates from Windows Update including Service Pack 1 for Team Suite or Service Pack 1 for Express Editions. If you run on Vista install the Service Pack 1 Update for Vista
3. You can optionally install WSS SDK an Office Server SDK also on your Workstation
4. Locate the Sharepoint Templates installed on the server environment and copy them to your Workstation User Templates. You have to navigate to:
“C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\CSharp”
and copy the whole Sharepoint Directory to your user Templates Folder on your Workstation. The Path is normally:
“C:\Users\<username>\Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual C#”.
If you want to develop in VB.NET do the same for the Sharepoint Folder in:
“C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\VisualBasic”
And copy it to:
“C:\Users\<username>\Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Basic”
Do the same for the Sharepoint Folders in the ItemTemplates Directory. There is only one for CSharp. Navigate to:
“C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp”
And copy the Sharepoint Folder to:
“C:\Users\<username>\Documents\Visual Studio 2005\Templates\ItemTemplates\Visual C#”
5. Copy the complete Folder “Microsoft Sharepoint Developer Tools”, which can be found in “C:\Program Files” on the Server or VPC to your Workstation machine in the same location.
6. In order to register the Projects, Packages and Templates on you Workstation machine you have to add several registry keys to your Registry. Here is the whole stuff, just copy and paste it in a text file and save it with a*.reg extension:


Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{041d4811-6ee8-4c3a-8981-ac53f22cf9cc}]
@="Microsoft.SharePoint.Tools.SdtProject"
"Class"="Microsoft.SharePoint.Tools.SdtProject"
"CodeBase"="C:\\Program Files\\Microsoft SharePoint Developer Tools\\package\\SPDevTools.dll"
"InprocServer32"="C:\\Windows\\system32\\mscoree.dll"
"ThreadingModel"="Both"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{c81fbc80-1a9b-4d76-81e4-bf729a27f9ac}]
@="Microsoft.SharePoint.Tools.Forms.DeployPropertyPage"
"Class"="Microsoft.SharePoint.Tools.Forms.DeployPropertyPage"
"CodeBase"="C:\\Program Files\\Microsoft SharePoint Developer Tools\\package\\SPDevTools.dll"
"InprocServer32"="C:\\Windows\\system32\\mscoree.dll"
"ThreadingModel"="Both"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\{bc426e8f-098f-47de-ad66-d11676c41c66}]
@="Microsoft.SharePoint.Tools.SdtPackage, SPDevTools, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
"ID"=dword:00000064
"Class"="Microsoft.SharePoint.Tools.SdtPackage"
"CodeBase"="C:\\Program Files\\Microsoft SharePoint Developer Tools\\package\\SPDevTools.dll"
"CompanyName"="Microsoft"
"InprocServer32"="C:\\Windows\\system32\\mscoree.dll"
"MinEdition"="Standard"
"ProductName"="SharePoint Developer Tools"
"ProductVersion"="12.0000.0000.0000"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\{bc426e8f-098f-47de-ad66-d11676c41c66}\SatelliteDll]
"DllName"="SPDevTools.dll"
"Path"="C:\\Program Files\\Microsoft SharePoint Developer Tools\\package"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\{9e5d3e2d-e4e2-418e-8d80-2f0da9a94f9a}]
"DisplayName"=""
@="SdtProjectFactory"
"DefaultProjectExtension"="csproj"
"DisplayProjectFileExtensions"="SharePoint Project Files (*.csproj);*.csproj"
"Package"="{bc426e8f-098f-47de-ad66-d11676c41c66}"
"PossibleProjectExtensions"="csproj"

#[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\NewProjectTemplates\TemplateDirs\{bc426e8f-098f-47de-ad66-d11676c41c66}]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\NewProjectTemplates\TemplateDirs\{bc426e8f-098f-47de-ad66-d11676c41c66}\/1]
@=""
"SortPriority"=dword:00000064
"TemplatesDir"="C:\\Program Files\\Microsoft SharePoint Developer Tools\\package"

Double click the *.reg File or import it using Regedit. In order to load the new package file, you maybe must start Visual Studio from the command line with the option /ResetSkipPkgs. Start a Command Window (on Vista this should run as an administrator) and navigate to:

“C:\Progarm Files\Microsoft Visual Studio 8\Common7\IDE”

And start Visual Studio via the following command:

Devenv /ResetSkipPkgs

Now you should be able to create new Sharepoint Projects like WebParts. To doublecheck this, in Visual Studio 2005 navigate to the Menu File->New->Project the Dialog Box should look like this:




Now select the Web Part and click Ok. Visual Studio should create the appropriate Project Files. If you click on References in the Solution Explorer you will see that there is an unresolved reference to the “Microsoft.Sharepoint” Assembly. So you can not yet build the WebPart or other Sharepoint Projects on the Workstation. Therefore the next 2 steps are necessary.

7. The Sharepoint Assemblies (DLLs) are located in the following Folder on the Sharepoint Server Installation:

“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI”

I copied the complete folder to the same location on my Workstation, but you can also only copy the assemblies, which start with “Microsoft.Sharepoint.*” to any folder on your Workstation.

8. In order that Visual Studio can automatically resolve the references you should add the assemblies to the Global Assembly Cache” (GAC). You can use the command line tool gacutil.exe or use the “Microsoft .NET Framework 2.0 Configuration” which can be found through navigating to Control Panel, then select “Administrative Tools”.

9. Now you should be able to generate and build Sharepoint Server 2007 related projects on a remote Workstation.


Deploying the Webpart Assemblies to the Server machine or VPC:

There are several ways to deploy Webparts to MOSS 2007. But I describe one way, which makes it easy during the development cycle to deploy and remote debug Webparts on the Server or VPC. In the VPC case you should ensure that you have network connection to the running VPC image.
1. If you starting with a new project and you do not want to reduce MOSS Security to fully trust all installed assemblies. You should sign your WebPart with a strong name and add the following line to your “AssemblyInfo.cs” in your project:

[assembly: System.Security.AllowPartiallyTrustedCallers()]


2. After a successful build you should copy your WebPart Assemblies to the \bin directory of your MOSS 2007 Server. I do this by adding a post build step to the project:


Where <server> must be replaced with your server or VPC image name.
The post build step is configured to be executed “When the build updates the project output”.

3. The next step is to add a safe control entry to the web.config of the Server. This looks like:

<SafeControls>
.
.
.
<SafeControl Assembly="MOSS2007_Test_WebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b76147539a074d8d" Namespace="MOSS2007_Test_WebPart" TypeName="*" Safe="True" />

</SafeControls>

The web.config is also located in the bin Directory:
C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin
in a default installation.

4. Navigate with the Browser to your target Site.
5. Click on Site Settings-> Modify all Site Settings
6. Click on Galleries -> Web Parts
7. Use the New Button to populate your Web Part to the gallery
I f your Web Part is not in the list, do an iisreset and try again. Normally the iisreset is not neccessary, but in some cases …
8. Now you can modify any page in your site and add you webpart to the page.

Now after a new successful build, the Web Part is copied to the server and is ready to be debugged.

Remote Debugging of Web Parts in MOSS 2007

1. In order to enable the Visual Studio remote debugging, navigate to “C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\x86” and start the “msvcmon.exe” on the server.
2. On the workstation in Visual Studio go to Debug -> Attach to process
3. In the Qualifier Text Box enter your server name
4. Check the Box: Show processes from all users.
5. Select *all* w3wp.exe processes using the control key on the keyboard
6. Click on Attach
7. Entry your breakpoints in the source code file in Visual Studio
8. Navigate or just refresh the Page, which has your control embedded and wait the breakpoint to be hit.

That’s it! Hope this procedures are somehow helpful to others, who want to develop Web Parts for MOSS 2007.