SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Sharepoint Team Development with Visual Studio 2005 2008 Part 3

This is the third and last part of Sharepoint Development using Visual Studio series. For previous part:
http://www.sharepointblogs.com/tommysegoro/archive/2008/09/04/sharepoint-team-development-with-visual-studio-part-2.aspx

Note: Just change the part-x bit to go to the other series of this posting. 

 

INTRODUCTION

I've shared to you about the different Sharepoint project types, the development methodology approach and the tools. In this particular posting I will share to you on how to plan your Sharepoint development. I've talked a bit about this in my previous posting about how you should plan your content types and fields first. Sure, requirements change but at least you reduce your "headache" if you can get as much content types and fields done as possible. In this particular posting I will share to you on how I normally approach the site creation, the implementation of features, etc.

 

THE TOOLS

Once again I will repeat this over and over again: You HAVE TO utilise solution and features deployment for team development. Please find on my previous post regarding the tools I've used. Anyway, I will use my own solution template for creating solutions and features on my examples/projects. Please download from http://www.codeplex.com/vs2008sp.

 

SITE CREATION

Personally I will go down the custom site definition path. I will not modify OOTB site definition (eg. modifying STS's ONET.XML directly) because when you start modifying OOTB files, they may get overridden by service packs or patches that Microsoft releases. With custom site definition, too you can select what features to be activated upon creating a new site, what files to appear, etc which makes sense for me.

My fellow Sharepoint developer mentioned to me before that he prefers to use PowerShell to activate the features because he can see whether feature activation succeeds or not rather than you create your site first then getting an error message. If any of you uses PowerShell to create your site/activate your features, can you please share your experience? Anyway, I personally will go down the custom site definition path because it's easier for me to categorise which site will use what features, which site use what pages, what lists to instanstiate, etc. See example below of my custom ONET.XML:

<Configuration ID="1" Name="Blank">
<
Lists>
<
List FeatureId="00BFEA71-2062-426C-90BF-714C59600103" Type="103" Title="Page Order" Url="Lists/Page Order" />
</
Lists>

<Modules>
<
Module Name="DefaultBlank" />
</
Modules>

<SiteFeatures>
<!--
BasicWebParts Feature -->
<
Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
<!--
Three-state Workflow Feature -->
<
Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
</
SiteFeatures>

<WebFeatures>

<!-- CUSTOM FEATURE -->
<!--
SITE ACTIONS -->
<
Feature ID="69CCBDEB-6B71-4fb6-9A2E-93EBB8D792D8" />

<!-- PUBLISHING LISTS CREATION -->
<
Feature ID="67A06416-3D36-44c9-8980-F10FA0181B27" />

<!-- SET PUBLISHING LIST WITHOUT APPROVAL -->
<
Feature ID="6873B8E8-848D-461d-9494-9422E354AE6B" />
<!--
MASTER PAGES -->
<
Feature ID="5522E091-66EA-40e8-9C62-D08861A96225" />
<!--
MODIFY NAVIGATION -->
<
Feature ID="2F74B5BA-BDA9-435d-84DC-DF3CA1E741A2" />

<
Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
<!--
TeamCollab Feature -->
<
Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4" />
<!--
MobilityRedirect --> <!-- CUSTOM FEATURES -->
<!--
Content Type Binding -->
<
Feature ID="678C0C06-1053-455b-8767-867B6B37EA75" />
</
WebFeatures>
</
Configuration>

Therefore, when I need to create a particular site that will require particular features to be activated, I can easily go to Site Actions -> Create Site and create a site that uses my custom site definition and it will then have the correct activated features.

For creating custom site definition I always start from the OOTB ones. To create WSS-related site definitions, start from STS. For Collaboration Portal starts from SPS and for MOSS Publishing starts from BLANKINTERNET.

 

THE PROJECT

I personally will divide the project into 3 sub-projects:
- Features
- UI
- DLL

The Features project will contain feature-related stuff (except features that deploy UI such as master pages, CSS, page layouts and javascripts). So in this project you will have features that contain feature receivers, features that deploy web parts, features that deploy content types and columns, etc.

The UI project will contain UI-related stuff such as feature that deploys master pages and page layouts, feature that deploys images, CSS and javascripts.

The DLL project contains all code-behind related stuff (feature receivers, event receivers, custom fields, user controls, web-part code, etc). Why I divide the code into a separate project? It's because when you're deploying the DLL it won't affect the other elements (eg. Features and UI). The other elements will still run as normal yet you can deploy as many changes to your code as possible.

 

UI ELEMENTS

I will deploy CSS and images that are related to the UI directly on file system using feature. I will not upload images that are related to UI to Sharepoint image library. The reason is, when it comes to updating them, it's very-very easy and quick to re-deploy a new set of CSS, javascripts or images to a file system rather than uploading those files to Sharepoint.

For master pages and page layouts, I will also move away from using Sharepoint Designer and I will NOT un-ghost them. Updating them will be very easy and they can be source controlled using TFS/VSS if you're not using Sharepoint Designer to update them. When you want to update them, you can just re-deploy your UI project and it will upgrade all of your master pages and page layouts in the file system.

 

CUSTOM PAGES FOR DISPLAYING NON-SHAREPOINT INFORMATION

Let's say you need to display information from your MS CRM but in the context of Sharepoint (and inheriting the Sharepoint permission for viewing that page, etc), I will personally go down the custom page layout (or application page path). This way you can then code your page to use Sharepoint permission. In your Sharepoint custom page you can then have user controls that will display information from MS CRM.

Example: http://myintranet/Pages/ViewCustomer.aspx or http://myintranet/_layouts/ViewAdmin.aspx.

 

TESTING

Various testings can also be executed on a Sharepoint application (same as usual custom applications). With unit testing however, you will need to have Sharepoint installed on your machine because stuff like retrieving list item from a list, etc will require you to connect to a Sharepoint list. When I divide my projects into those 3 categories, I can easily test the DLL project without even deploying my UI and my Features (although I will need to have the actual list to be created on my Sharepoint site if I need to retrieve items from it).

 

DEVELOPMENT PROCESS

The development process can be the same per general custom application development. With those 3 sub-projects I have, I can check-in check-out files/features/user controls/master pages, etc and my fellow developers can then get latest and run Install/Upgrade and he will suddenly have the latest files on his Sharepoint site. That's the beauty of solution and feature deployment. It allows you to do team development.

 

BUILD and UAT PROCESS

The build and UAT process can also be the same as per general custom application development. I can use TFS (or other tool) to build my 3 sub-projects, deploy the features/solutions to the Test server then I can run Install/Upgrade script. The Sharepoint site on the Test server will then have the latest features and files installed.

 

CONCLUSION

So this will be the end of the team development series hope that you enjoy reading them and please share your experience. The team development process may take more time than just modifying things directly through the Sharepoint GUI but it's worth it. It will make your code maintenance a lot easier, it also allows you to perform code review (making sure that everyone is on the same page in terms of writing feature, code and solutions) and updating/upgrading your files will be a lot easier.

To download sample code please go to http://www.smallbusinesshosting.com.au/SampleProject.zip.

Cheers.


Posted 09-25-2008 11:31 AM by tommysegoro

Comments

James wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 09-26-2008 8:04 AM

I would love to see a sample project using your 3-project system. I'm currently a bit confused as it seems certain bits overlap between projects (for example Feature Receivers.). Otherwise thanks for these articeles, very helpful.

Jeremy Thake wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 09-27-2008 4:39 AM

Tommy, out of interest, when you say you seperate the dll project from your features. There are dependencies between these two, for example, if you have a feature receiver - the code is defined in the feature element and you will have the Feature Receiver code in a seperate project.

I'm thinking, in large projects that this will lead to a lot of too'ing and fro'ing between projects. Why not go for the approach of having your code in the same project as the features if they are so dependent on each other?

IF you use STSDEV, you can actually run a command that simply deploys the dll to the GAC without relying a redeployment of the solution itself. This would resolve your reasoning for separating them.

Be interested to hear your thoughts.

Links (9/28/2008) « Steve Pietrek - Everything SharePoint wrote Links (9/28/2008) &laquo; Steve Pietrek - Everything SharePoint
on 09-28-2008 6:56 PM

Pingback from  Links (9/28/2008) &laquo; Steve Pietrek - Everything SharePoint

Emad wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 09-29-2008 12:43 AM

Could you please help me with webparts. To my understanding there are two best ways to deploy web part. First of all I need user control since I have UI experience. So either I need to use smart part then I have no Idea how can I use solution deployment? or using an inline code user control and web custom control. the user contorl is loaded to web custom control. then I can use solutuion. in second way you need use inline coding which is awful. What is your approach to deploy web parts and using solutions.

tommysegoro wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 09-29-2008 6:00 AM

Hi Jeremy,

In big projects I even prefer put all feature receivers into the same DLL because it's easier to manage. You can have FeatureReceivers folder and the namespace can be something like:

MyProject.Core.FeatureReceivers.MyReceiver

And you can organize them into one project while if you're using STSDEV, you have to remember/document which projects have what since you can create different type of projects with it.

That's why I personally would like to organise all my code-behind-related files into one project and just have another project that deploys all my features.

Cheers,

Tommy

tommysegoro wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 09-29-2008 6:03 AM

Emad,

With your question, you can also deploy user controls using my solution template, can't you? Just put them under 12/CONTROLTEMPLATES/MyClient/ControlName.ascx then in your web-part you can then reference this control, can't you?

That's how I personally approach web-part deployment. All the DWP, user controls and the actual web-part DLL itself can be deployed using my solution template. If you need help to deploy ASCX, web-part and DLL using my solution template please let me know I can send you a sample project.

Cheers,

Tommy

tommysegoro wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 09-29-2008 9:18 AM

To everyone who is interested in my project structure please go to www.smallbusinesshosting.com.au/vs2008sp for the solution template or go to:

www.smallbusinesshosting.com.au/SampleProject.zip

to download the sample code.

Ram wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 10-02-2008 5:36 PM

Hi Tommy,

Thank you for the article. I ran the sample project in VS 2008, and everything got build perfect. But when I ran the install.cmd file under Features, i got the following error:

bin\debug\SampleProject.Features.wsp: The specified file was not found.

is there anything i need to do to generate the wsp file ? I'm a newbie and would appreciate any comments from you.

Thanks

Ram

tommysegoro wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 10-02-2008 7:30 PM

Ram,

Where do you run the Install.cmd from? If you run it from Visual Studio using the InstallSolution build command then it will build ok but if you double click on the file, just remove the "bin\debug\" bit so it will run the WSP from the same location of the Install.cmd file.

If you don't remove the "bin\debug\" it will look for WSP in the "bin\debug" folder relative to there the Install.cmd file is located.

Cheers,

Tommy

jagadeesh wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 10-03-2008 4:15 AM

can u please give sample project to develop share point site defination in vs 2005

Tommy Segoro wrote Sharepoint Team Development with Visual Studio 2005 2008 Part 4
on 10-10-2008 1:11 AM

INTRODUCTION Hello hello...I&#39;ve said in my last post www.sharepointblogs.com/.../archive

Alex wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 10-27-2008 6:58 AM

Hello Tommy,

First of all - congratulations and thanks for sharing this great and helpful work!

I am now starting to develop on top of Sharepoint. What would be the best way to "include" a new HelloWorld web part on your Sharepoint solution template? I am assuming the .cs file under the DLL project and the feature under the features project but I am a bit lost about how to configure the feature.xml file (for instance, how do I generate the id)  for that web part and how to make sure the web part is built and deployed together with the rest ? An example would be great! Thanks!

Cheers,

Alex

tommysegoro wrote re: Sharepoint Team Development with Visual Studio 2005 2008 Part 3
on 10-27-2008 1:55 PM

Alex,

That will be correct. The .cs file can be on the DLL project and the feature is in the Feature project. To generate the ID you can use the Create GUID tool. Go to Tools -> Create GUID.

To download sample project go to www.smallbusinesshosting.com.au/SampleProject.zip.

Cheers,

Tommy

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.