Logo
CAR REVIEW
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
Windows Server

Developing with SharePoint 2010 (part 1) - Platform Development Tools, Development Server Configuration

2/6/2013 4:33:48 PM

1. Platform Development Tools

One of the big improvements in SharePoint 2010 is its tooling. In previous versions, platform developers were forced to rely on home-grown or community-supported tools to get any serious development efforts off the ground. Using Visual Studio 2010, developing solutions that target the SharePoint platform is much easier because of a number of new SharePoint-specific integrated development environment (IDE) tools and project templates.

Visual Studio 2010 and SharePoint Designer 2010

In addition to Visual Studio 2010, many improvements have been added to SharePoint Designer 2010. When it comes to doing any design work in SharePoint, SharePoint Designer has always been the way to go. Using the combination of Visual Studio and SharePoint Designer provides practically all the tools that we need to develop SharePoint platform applications.

TypeMock Isolator

Having said that, there are still a few areas that aren’t addressed by the combination of Visual Studio and SharePoint Designer. For example, when it comes to test-driven development, isolating dependencies to test custom SharePoint code can be challenging. Common practice would mandate the use of a mocking framework, but many of the classes in the SharePoint object model are sealed, making them difficult to mock. To address this particular problem, TypeMock Isolator provides a dependency isolation tool that is both integrated with Visual Studio 2010 and able to mock SharePoint sealed classes. In effect, we can write automated unit tests for SharePoint without actually touching the SharePoint platform.

Red Gate .NET Reflector

The sheer complexity of the platform is another area where a third-party product can help, and this issue will be the source of much frustration for any developer building a complex business application on the SharePoint platform. Of course, plenty of documentation is available to help, but there will come a time when a piece of code just doesn’t behave as you expected.

Experienced developers will be aware of .NET Reflector, a tool that is capable of disassembling .NET assemblies to expose their inner workings. When things don’t behave as expected, the only way we can move forward is to disassemble the application binaries and try to work out what’s going on. This works well, but it can be time-consuming and difficult to track what’s going on in disassembled code. To make this process much easier, Red Gate provides the .NET Reflector Pro product. The product runs as an add-in to Visual Studio 2010 and allows developers to debug third-party assemblies. Or in other words, when things don’t go according to plan, we can step in to the SharePoint assemblies and track down exactly where the problem lies in the same ways we use to debug our own code.

Sysinternals DebugView

A lot of the code we write when developing SharePoint applications runs behind the scenes. It can be difficult to connect a debugger to the process in which much of this code runs without causing system instability. Furthermore, when an application is deployed to a farm environment, the problem is compounded by the fact that our code is running in more than one server. A few solutions to this problem are possible. The SharePoint platform provides a Unified Logging Service (ULS) that is intended to be a central source for all tracing and logging information, and this works well when tracing information needs to be included in context with other SharePoint-generated messages. The drawbacks to this approach are the relative complexity of using the ULS logs and the sheer volume of data produced in the logs. In my experience, the easiest way to debug programming errors in a complex application is to make use of Sysinternals DebugView. By simply adding Trace.Write and Debug.Write statements throughout our code, we can view the output at runtime using the DebugVew user interface.

SharePoint 2010 provides a few new tools that make it much easier to troubleshoot performance issues or debug code that runs in a user-initiated process such as a web page.

2. Development Server Configuration

For development purposes, SharePoint 2010 can be installed on either a 64-bit Windows 7 or Windows Vista SP1 client machine or a 64-bit Windows 2008 or Windows 2008 R2 server.

Defining an SPRoot Environment Variable

By performing a standard installation of SharePoint, most of the program files are installed at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\.

Take the following steps:

  1. Open a command prompt window.

  2. Enter the following command:

    setx SPROOT "C:\Program Files\Microsoft Shared\Web Server Extensions\14\
    

Note

The omission of quotation marks at the end of the command line is intentional.


Using Office Applications in Windows 2008 Server

Because Windows Server 2008 is not deigned to be a client operating system, some of the integration features of products such as Word 2010 don’t work as you would expect. All Office 2010 applications come with a new backstage area that, among other things, allows users to publish documents easily to SharePoint document libraries. For this feature to work correctly on Windows 2008, the Desktop Experience feature must be enabled. To enable the Desktop Experience feature, take the following steps:

  1. Open the Server Manager application.

  2. Select the Features node, and then click the Add Features button link.

  3. In the Add Features Wizard dialog, select the Desktop Experience feature.

Debugging and Unit Testing SharePoint Applications

SharePoint 2010 is a 64-bit application. Therefore, all the code that we write that will run within SharePoint-managed processes must also be 64-bit. This detail can cause a bit of confusion, especially when you’re trying to debug console applications or run automated unit tests.

To illustrate this point, suppose we have the following simple event receiver:

public class DemoEventReceiver : SPItemEventReceiver
    {
       public override void ItemAdding(SPItemEventProperties properties)
       {
         using (SPWeb web = properties.OpenWeb())
         {
           web.Title = "Some New Title";
           web.Update();
         }
       }
    }

We could create the following unit test using TypeMock Isolator:

[TestMethod()]
    public void ItemAddingTest()
    {
      DemoEventReceiver target = new DemoEventReceiver();
      SPItemEventProperties properties = Isolate.Fake.Instance<SPItemEventProperties>();
      using (SPSite site = new SPSite("http://sp2010dev2/"))
      {
        using (SPWeb web = site.RootWeb)
        {
          Isolate.WhenCalled(() => properties.OpenWeb()).WillReturn(web);
          target.ItemAdding(properties);
          Assert.AreEqual(web.Title, "Some New Title");
        }
      }
    }


					  

When running this test within Visual Studio, a System.IO.FileNotFound exception is thrown, suggesting that the web application could not be found.

This error is misleading; if the site URL is correct, most likely the error is being thrown because we’re trying to use the SharePoint object model from within a 32-bit application. Although Visual Studio supports 64-bit code, by default many projects are created in 32-bit mode, particularly console applications, as you’ll see later. Also, the test runner within Visual Studio runs as a 32-bit application, meaning that unit tests cannot connect to SharePoint objects. Although you can force the test runner to use 64-bit, this uses a different test runner that runs as a .NET 4 application; as a consequence, SharePoint is not supported, since it is based on .NET 3.5.

All is not lost, however; when creating unit tests, it’s generally considered good practice to isolate all dependencies, and with clever use of TypeMock, we can change our unit test as follows:

[TestMethod()]
    public void ItemAddingTest()
    {
      DemoEventReceiver target = new DemoEventReceiver();
      SPItemEventProperties properties = Isolate.Fake.Instance<SPItemEventProperties>();
      SPWeb fakeWeb = Isolate.Fake.Instance<SPWeb>();
      Isolate.WhenCalled(() => properties.OpenWeb()).WillReturn(fakeWeb);
      target.ItemAdding(properties);
      Assert.AreEqual(fakeWeb.Title, "Some New Title");
      Isolate.Verify.WasCalledWithAnyArguments(() => fakeWeb.Update());
    }


					  

This time, the test passes as expected, because even though our code is being fully tested, since we’re using mocked SharePoint objects rather than real objects, the test runner can execute our test in 32-bit mode.

Other -----------------
- SQL Server 2008 R2 : Creating and Managing Stored Procedures - Viewing Stored Procedures
- SQL Server 2008 R2 : Creating and Managing Stored Procedures - Deferred Name Resolution
- Using Microsoft SharePoint with Microsoft Dynamics CRM Functions (part 2) - Displaying Data Using BDC in Microsoft Office SharePoint Server
- Using Microsoft SharePoint with Microsoft Dynamics CRM Functions (part 2) - Displaying Data Using BDC in Microsoft Office SharePoint Server
- Using Microsoft SharePoint with Microsoft Dynamics CRM Functions (part 1) - Displaying Data in SharePoint Using the List Web Part for Microsoft Dynamics CRM 4.0
- Microsoft Exchange Server 2007 : Single Copy Clusters (part 2) - Installing Exchange Server 2007 on the Active Node
- Microsoft Exchange Server 2007 : Single Copy Clusters (part 1)
- Windows Server 2003 on HP ProLiant Servers : Logical Structure Design (part 5) - Trust Definitions
- Windows Server 2003 on HP ProLiant Servers : Logical Structure Design (part 4) - Group Policy
- Windows Server 2003 on HP ProLiant Servers : Logical Structure Design (part 3) - Naming Standards
- Windows Server 2003 on HP ProLiant Servers : Logical Structure Design (part 2) - Forest Structure, OU Structure
- Windows Server 2003 on HP ProLiant Servers : Logical Structure Design (part 1) - Domain and OU Structure
- Microsoft Dynamics GP 2010 : Preventing Errors in Dynamics GP - Ensuring proper year-end closing by checking Posting Types
- Microsoft Dynamics GP 2010 : Preventing Errors in Dynamics GP - Preventing account selection errors with Chart Segment names
- Monitoring Windows Small Business Server 2011 : Using Windows SBS Console Monitoring (part 3) - Creating and Viewing Reports
- Monitoring Windows Small Business Server 2011 : Using Windows SBS Console Monitoring (part 2) - Using Notification Settings
- Monitoring Windows Small Business Server 2011 : Using Windows SBS Console Monitoring (part 1) - Using the Network Essentials Summary
- System Center Configuration Manager 2007 : Operating System Deployment - Boot Images
- System Center Configuration Manager 2007 : Operating System Deployment - Site Systems
- BizTalk Server 2006 : Pipeline Component Best Practices and Examples - The Databased Disassembler
 
 
Most view of day
- Microsoft Dynamics CRM 2011 : Using Advanced Find (part 5) - Using Edit Multiple Records and Assign Multiple Records from Advanced Find
- Sharepoint 2013 : Backup and Restore (part 2) - Export and Import - Using PowerShell, STSADM, Central Administration
- Microsoft Exchange Server 2007 : Understanding the Client Access Server (part 4) - Availability Service, POP and IMAP
- Windows Phone 8 : Configuring Basic Device Settings - Date and Time (part 1) - Setting the Date and Time
- Duplicating and Copying DVDs (part 3) - Ripping DVDs in H.264 Format
- BizTalk 2006 : Getting Started with Pipeline Development (part 1) - Pipeline Stages
- Fine-Tuning MDT Deployments : Working with the MDT Database (part 4) - Extending the MDT Database with Custom Settings
- Microsoft Systems Management Server 2003 : Custom SMS Administrator Consoles
- Windows Phone 8 : Developing for the Phone - The Phone Experience (part 1) - Orientation
- Windows Phone 7 : The Silverlight Controls (part 3) - Line, Polyline, and Polygon Controls
Top 10
- Windows Phone 8 : Scheduled Tasks - Scheduled Task API Limitations
- Windows Phone 8 : Scheduled Tasks - Updating Tiles Using a Scheduled Task Agent
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 5) - Editing an Existing To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 4) - Creating the To-Do Item Shell Tile, Saving a To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 3) - Debugging Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 2) - TodoService, TodoItemViewModel
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 1) - TodoItem,TodoDataContext
- Windows Phone 8 : Scheduled Tasks - Using Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - Background Agent Types
- Windows Phone 8 : Windows Phone Toolkit Animated Page Transitions - Reusing the Transition Attached Properties
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro