Skip to main content

technical blog

Go Search
Home
Technical Blog
My CV
Travel
Skydiving
Wedding Photos
Contact
  
Random Image

chrishines.com > technical blog
SharePoint and other Technology I work with.
Stopping Time
When working in a Microsoft Virtual Machine (VPC or Virtual Server) the virtual will periodically synchronize the clock with the host's clock. This can be a pain when trying to test your code with future or past dates. However, it is possible to stop this synchronization:
 
In Virtual Server
 
Edit the .vmc file. Find the components tag and add/modify the host_time_sync value to false
 
e.g.
 
<components>
  <host_time_sync>
    <enabled type="boolean">false</enabled>
  </host_time_sync>
</components>
 
 
In Virtual PC
 
Stop the 1-vmsrvc service.
 
e.g.
 
net stop 1-vmsrvc
 
This will break the ability to copy files into the VM. However, restarting the service will get things working again.
 
(Thanks to Stuart Lally for pointing this out to me)
 
SharePoint Error Page
There are two steps you need to perform in order to configure SharePoint for detailed ASP.Net error messages,  avoiding the standard SharePoint Error screen (which is sometimes not very informative). I always forget the second step so I thought I'd write it down here!
 
Modify web.config in two places....
 
1. Change the customErrors mode to RemoteOnly:
 
<configuration>
  <system.web>
    <customErrors mode="RemoteOnly" />
 
2. Set the SafeMode CallStack to true:
 
<configuration>
  <SharePoint>
    <SafeMode CallStack="true"
 
You will now get detailed ASP.Net error messages when browsing locally on the SharePoint server.
SharePoint SDK Update
Last week Microsoft announced an update to the SharePoint SDK. I'm really pleased there is now much more flesh on the bones of the documentation! This should make straying into new areas of the Object Model easier.
 
 
The big news surrounding the release is that there is now a Business Data Catalog (BDC) Definition Editor to help you generate XML application definitions. This is fairly bad news for Nick Swan's BDC Metaman because he now needs to differentiate his tool from a free alternative. That said, in his Blog post on the subject he remains fairly upbeat about the whole thing. The guy is clearly very knowledgeable about the BDC and its potential so will, I'm sure, remain an authority on the subject. I would also like to bet that BDC Metaman will offer more advanced features and be able to respond much more quickly to market demand than Microsoft's tool. I will watch with anticipation....
SharePoint 2007 Exam – Experience Counts
I have been working with SharePoint since 2004 and version 3.0 of the product almost exclusively since September 2006. With one full lifecyle 2007 project behind me I thought I would take five minutes out to try one of the new SharePoint 2007 specific exams. I did very little preparation but instead decided to rely upon my experience. I took 70-541, Windows SharePoint Services 3.0 Application Development, yesterday and passed! So I’m now a Microsoft Certified Technology Specialist for SharePoint Services 3.0 Application Development. I hope to take the SharePoint Configuration and MOSS specific exams in the near future...
Finally! A direction for SharePoint Accessibility
Hi Software are developing an Accessibility Kit for MOSS 2007.
SharePoint 2007 Development - Build Processes
A couple of weeks ago I wrote about how my team uses a 100% Virtual development environment, the first half a SharePoint developer’s “green field” as I described it. Another major factor in creating a happy and efficient development team is putting the effort into designing good build processes. There are many variations on a theme when it comes to building SharePoint 2007 projects but I thought I would write down an overview of how we do it so as to “add to the mix”!
 
Why not just use the Visual Studio Extensions for SharePoint?
 
 
We looked at using these around Feb 2007 when they were still in Community Release and had a bad experience. They were very buggy (ok fair enough at the time) but most importantly we had little control over the SharePoint Solution Files (WSPs) being generated. We could neither structure the Feature directories the way that we wanted nor name the Features the way we wanted. The build was very much “all or nothing” i.e. a full build was performed each time, along with deployment to the server. In addition, the build process was very hard to debug when something went wrong. There’s a relevant discussion thread on SUGUK talking about these kinds of issues.
 
So with the need for a high degree of control over our WSP files and the desire to create an efficient build we set about designing our own...
 
Pretty quickly we decided that it would be easier to manage and probably most logical to functionally separate our projects into:
 
  • WebParts – WebPart code and resource files
  • SiteTemplate – Everything CAML based
  • Components – 3rd party assemblies and resource files.
  • Webservices – Webservice asmx and supporting assemblies.
Each of these projects would result in the generation of a corresponding WSP file ready to deploy to the development server. In this article I will explain the build process for the SiteTemplate and WebParts project because they demonstrate two slightly different techniques which can then be reused elsewhere.
 
Site Template Build
 
Site Template Build
Fig. (1)
 
 
When laying out SharePoint Features I find it most logical to replicate how the Feature will eventually appear when it is deployed on to the Front End Webserver in the “12 Hive”. Fig.(1) shows an example list, Aeroplanes, which has the usual xml files you’d expect for a List Feature.
 
On a successful build of the project the Post-build.bat file is called from the Post-build events (under Project Properties). The reason there is a separate file is because I hate the nasty Post-build event editing window in Visual Studio! It’s just horrid. Seeing as the Post-build events need to be edited quite a bit, it’s much easier to have the file right there in your Project so you can just double click to get editing.
 
The Post-build.bat scripts the whole build process and in Fig.(1) I have documented pseudo code for each of the steps it goes through. I’ll detail the steps a bit more...
  • First up MakeCab.exe is used to generate a WSP file. A WSP is just a CAB file with a WSP extension. The MakeCabDirectives.ddf file is passed to the MakeCab.exe to define the WSP payload and so therefore lists the Feature xml files as well as the all important Manifest.xml.
  • If the WSP generation is successful then we move on, if it’s not we’ll see some error messages in the Visual Studio Output window.
  • The next steps remove any previously deployed versions of the WSP. Of course first time round these steps will fail because there will not be anything to remove.
  • Then we begin the deployment steps. First we deploy the WSP to the SharePoint Solution Store using STSADM. We then have the choice of how we deploy the WSP, in development I always deploy globally where possible. The final step of deployment is to activate Features on any specific development sites.
  • Inserting entries into web.config could be a requirement for many different SharePoint projects. However, we put all the modifications into the SiteTemplate project because it felt like the most sensible place to keep them (they have to go somewhere). We actually keep these modifications in an XML file (not shown in the diagram) and then apply them using the SharePoint Object Model as shown.
  • Finally we perform an iisreset in case any of the CAML changes require it.
WebParts Build
 
 
WebParts Build
Fig.(2)
 
There are actually two projects which make up CMH.WebPart development, CMH.WebParts and CMH.WebPartsWSP. The former contains all of the WebPart code and resource files, the latter contains the files for packaging as a WSP. We’ll look at CMH.WebpartsWSP first...
  • CMH.WebpartsWSP is dependent upon CMH.WebParts, so first of all the build will compile the assembly CMH.WebParts.dll.
The CMH.WebPartsWSP  Post-build.bat will then run...
  • Again we use MakeCab.exe to generate a WSP, this time it contains the WebPart assemblies and resource files.
  • We then retract and delete any existing solutions using STSADM.
  • Next we add the WSP to the solution store using STSADM and then deploy the solution to a known application, also using STSADM.
  • Finally, for good measure, we perform an iisreset.
The building of CMH.WebPartsWSP represents a “full” build, replacing all files associated with the WebParts. It’s worth noting that the Manifest.xml contains instructions for SharePoint to update its Safe Control list and Code Access Security to facilitate the running of the WebPart. So the WSP deployment really does contain everything the WebPart will need.
 
The only downside to a full WSP build and deploy is that it can take quite a long time. This is why we have the separate CMH.WebParts project. Once a full WSP build has been done we can then just replace the CMH.WebParts.dll in the SharePoint bin in order to make changes to the code. WebPart development mostly involves a code-change-then-test cycle, so for the majority of rebuilds all we need to update is the assembly. So, in the CMH.WebParts Post-build.bat we copy the assembly from the output target to the SharePoint bin. To test the changes all we need to do is refresh the WebPart page.
 
Fig.(2) also shows a QuickDeploy.bat script. This is not called as part of the build process but instead a developer can optionally run it in order to copy resource files directly to the 12 Hive (or resources directory). It’s a quick way to get resource changes into a SharePoint site for testing e.g. changes to Javascript files without having to go through a full build. There is one downside, when you subsequently try to retract the solution SharePoint may not be able to retract these files because it can see they have been modified.
 
One other useful thing we do in CMH.WebParts Post-build.bat is use sn.exe to output the Public Key Token for the signed CMH.WebParts.dll. This is useful because the Public Key Token is needed when writing the Manifest.xml file as well as .webpart files for each WebPart.

There you go! Some SharePoint build processes. Whilst not totally original I think they contain some nice ideas and have certainly proven to work well during the past 6 months of our project. 

Just recently I was referred to:
 
 
When I have time I would like to incorporate these scripts to take the manual work out of writing .DDF files. You may want to check them out.
 
Telerik Controls and SharePoint 2007
A few months back I wrote a nice Visual Studio project to wrap up the Telerik r.a.d.treeview and r.a.d.window into a SharePoint 2007 WSP so that we could easily deploy these controls as part of our solution. I've been using the Telerik controls for a couple of years now and really rate them. We use the Treeview for our main navigation and the Window for things like our context sensitive Help.
 
I just read on Andrew Connell's Blog that he's been helping Telerik put together a White Paper and some tools to make this kind of thing easier. Check out Telerik's White Paper here. Without the aid of the tools I have been manually writing the .ddf and Manifest.xml which is fine for how we are using the controls because we don't need all of the skins etc. However, now these tools are available I may switch to using them as it is what's recommended.
 
Perhaps Telerik should release their r.a.d controls as ready-to-go WSP files!?
VM Performance Checklist
Just saw an interesting article about VM performance which would be useful in relation to my last post about a SharePoint 2007 Development Environment.
 
 
Most of the check points will be relevant for a SharePoint 2007 VM. However, I would say that no matter how well optimized the Host and the VM are you are never going to get SharePoint 2007 to run well with only 512MB of memory! On our old laptops with 2GB Memory we found the optimum allocation to the VM was about 1200MB.
SharePoint 2007 Team Development Environment
I was once told that developers are like cows, put them in a nice field full of green grass and they will be both happy and yield milk! I think that part of making a developer’s green field is to design an efficient, easy-to-use environment which enables them to get on with their job more easily.
 
When our team began to work with SharePoint 2007 we decided to rethink our development and build processes in light of new tools at our disposal. To give a brief summary of what we do: our remit is to develop Portfolio, Programme and Project Management tools using Microsoft Project Server and SharePoint to support our Programme Improvement service. Our tools need to offer a high degree of customization to both Project Server and SharePoint as well as be very flexible and repeatable to support different client implementations. Basically, we do a lot of customization at the code level.
 
Whilst there have been huge improvements made to SharePoint Designer (previously called Front Page) this tool does not offer the low level customization we need nor the facilities for us to build replicable and flexible solutions. We use Visual Studio to develop customizations for Project Server, SharePoint and also to develop Reporting Services Reports.
 
By the time we started with SharePoint 2007 we were already using Virtualization but felt that we should be doing more with it. So we set out to virtualize everything, including our development tools. This begun with us building one Virtual Machine using Microsoft Virtual PC, the build was:
  • Windows 2003 Server (SP1)
  • SQL Server 2005
  • Reporting Services
  • Project Server 2007
  • SharePoint (WSS) 2007
  • Visual Studio 2005
The great thing about putting Visual Studio into your SharePoint VM is that the SharePoint environment becomes very accessible to you. For example you can reference the SharePoint assemblies for programming with the Object Model or reference XSDs to give your XML/CAML development IntelliSense. Another major advantage is that it becomes very easy to attach to the w3wp to debug WebPart assemblies.
 
We ran this VM using Microsoft VPC on a single processor laptop with 2GB of RAM. Using Todd Bleeker’s StopDeveloperSericesVPC.cmd and setting the VM’s memory to 1200MB we achieved reasonable performance.
 
Based upon this success we began to clone the VMs using NEWSID to give us more copies for the other developers on the team. However, we quickly discovered that SharePoint 2007 and Project Server 2007 do not respond well to NEWSID so we had to clone the VM prior to the installation of these products i.e. on each new VM we had to install SharePoint and Project Server again. Not ideal, but better than starting from scratch each time!
 
Each new VM was given its own name VM01, VM02 etc and allocated a static IP address in the same range. Each developer on the team took their own VM and ran it on their own laptop hooking it up to their laptop’s network adapter.
With the VMs in place we set up a Visual Source Safe running natively on a sever with an IP address in the same range as the VMs. Pass-through authentication was the fastest way to authenticate each developer on the server i.e. each developer would log into their own VM with their own account and then the account would be replicated on the Source Safe server with the same username and password.
 
It was at this point we hit some major concurrency issues when checking in and out of Source Safe. Everything worked well until more than one developer tried to use Source Safe at one time! Through persistence and with a bit of luck we found a solution to the problem. We found that if we setup our VPC to have the Microsoft Loopback Adapter at position one in the Network Adapter settings and then the real network adapter at position two we were able to work concurrently. We’ve still not found an explanation for why this works but interestingly enough the problem went away when we moved to using Microsoft Virtual Server R2 in place of Microsoft Virtual PC.
 
For the best part of the last six months we have been working using single processor IBM laptops with 2GB of RAM. However, we’ve recently taken delivery of some new desktop development machines which are of a much higher spec (see diagram below). Whilst the laptops offered acceptable performance things have become a lot easier on the new machines.
 
Here’s what our current development environment looks like:
 
SharePoint 2007 Development Environment

I would definitely recommend working in a similar way to this when developing for SharePoint 2007 (and indeed Project Server 2007). It’s proven to be an efficient environment which is easy to setup when we have new developers join the team or when we need to throw away our VM and start again.
 
I’ll try to find the time to write about our build process because I think this is the second half of the developer’s green field….
 
SharePoint List Definition – Repetitive CAML
I have fired this question into Microsoft with no response as yet. It’s not a major problem but does make list definition in CAML feel a little clumsy….
 
In order to develop a fully functioning custom list with custom columns (fields) I need to:
 
Define all of the list fields as Site columns
e.g.

<Field ID="{D9DFD968-DB72-4b47-93C5-333F0959C247}"
  Name="MyField"
  SourceID="http://schemas.microsoft.com/sharepoint/v3"
  StaticName=" MyField"
  Group="CMH"
  Type="Note"
  DisplayName="My Field"
  NumLines="5"
</Field>
 
Then define a Content Type including all the List's columns
e.g.

 
<ContentType ID="0x0100D767501FD80F4d16ADABFB50EFDE0B8B"
  Name="MyContentType"
  Group="CMH"
  Description="My Content Type"
  Sealed="FALSE"
  ReadOnly="FALSE"
  Hidden="FALSE">
  <FieldRefs>
    <FieldRef ID="{D9DFD968-DB72-4b47-93C5-333F0959C247}"
      Name="Problem"/>
  </FieldRefs>
</ContentType>
 
Then Reference the Content Type in the List’s SCHEMA.xml
e.g.

 
<ContentTypes>
  <ContentTypeRef ID="0x0100D767501FD80F4d16ADABFB50EFDE0B8B">
    <Folder TargetName="MyList"/>
  </ContentTypeRef>
  <ContentTypeRef ID="0x0120" />
</ContentTypes>

Then redefine i.e. repeat exactly the Field definitions in the List's SCHEMA.xml
 
<Field ID="{D9DFD968-DB72-4b47-93C5-333F0959C247}"
  Name="MyField"
  SourceID="http://schemas.microsoft.com/sharepoint/v3"
  StaticName=" MyField"
  Group="CMH"
  Type="Note"
  DisplayName="My Field"
  NumLines="5"
</Field>
 
This appears to be very repetitive! The main symptom I first noticed was that if I did not define a Content Type for the fields then the Fields do not appear in the New or Edit Item forms. Have I missed something? Why is it so repetitive?
1 - 10 Next

 ‭(Hidden)‬ Admin Links