Thursday, April 16, 2009

Disable Loopback Checking on Windows Server 2003

I updated my Windows Server 2003 running on a VMware image with the lasted April 2009 updates from Microsoft this morning. The result was that none of my SharePoint sites worked afterwards. The solution for me and one of my colleagues turns out to be this old known issue
http://wcornwill.wordpress.com/2006/06/06/mapping-host-headers-causes-looping-windows-authentication/
and
http://www.sharepointblogs.com/george/archive/2009/04/16/error-401-connecting-to-local-iis-website-after-3-credential-prompts.aspx

I would only recommend to disable the Loopback checking for developing environments.

Disable Loopback Checking

  1. open regedit
  2. Find HKLM\System\CurrentControlSet\Control\Lsa
  3. Create a new DWORD value called DisableLoopbackCheck and give it a value of 1
  4. Restart the computer


Tuesday, April 14, 2009

Developers 10 Commandments for preventing errors

Over the years of programming, I have gone from a simple spaghetti developer to an object oriented, method mineralized, property loving, defensive coding and structure focused (spaghetti) developer. So what is the difference? When I think about it, my code may look like a spaghetti program today, for the untrained eye that is, because of object inheritance, events, properties and so forth. But it's much better organized than it was just 20 years ago. The big advantage is that it is much easier to spot and avoid errors than in the good old spaghetti programming days. But I still need to avoid programmatic and logic errors, therefore I follow these 10 basic commandments in writing code.

  1. Assumptions are the mother of all errors.
  2. The most lacy developer do things right the first time.
  3. If something can go wrong, then it will at some point do.
  4. Never implement bad exception handling. Like the Ostrich-algorithm, where you put your head in the ground and pretend that nothing has happened.
  5. Know your events or you program will fail.
  6. Errors usually appears where you least expect them to.
  7. Users come from the dark side and they got errors with them.
  8. Unit test... unit what?
  9. Keep it simple! However this does not apply for the female developers, they are able to multi task!
  10. Always include a dead-man switch in a While loop, if it potentially can loop forever.

You will find some of the commandments more relevant than others but they all still holds an important message.

Defensive programming (link)

When using a defensive programming strategy and following the commandments I tend to think what can go wrong in my code and how to prevent it from doing so or simply handling it. This turns into rock solid applications that help me sleep better at night. The effort required is actually less than that of the ordinary "spaghetti code", because you don't spend the time constantly debugging your code in the end when the users keeps coming back with new errors that they have found.

Three strikes and you're program is out.

In the beginning when a user first starts to use a program, they have the stomach for three errors before they tend to give up on it and look for another solution. Therefore it's very important that the users are not presented with the errors directly in the face every time something goes wrong. Fallback gracefully when an error occurs is very important so the users don't feel abandoned.

Detailed description of the commandments.

  1. Assumptions are the mother of all errors.
    Picked up from the movie Under Siege 2: Dark Territory (1995), where one of the bad henchmen (Penn) believes that he has killed Casey Ryback (played by Steven Seagal), but it's just an assumption and therefore Ryback is able to continue haunting the bad guys and finally finishing them off (think of yourself as one of the bad guys :-) The same thing applies to code - when you assume something will work, it will for sure come back to haunt you. (Nobody wants a Ryback running around and destroying their program). Every error in a program is there because the developer assumed that it was fine there was no possible scenario for an error. Don't make assumptions – know for sure and handle any possible outcome!

  2. The most lacy developer do things right the first time.
    If you want to save time and errors when creating a program, do things right the first time. Otherwise you just end up forgetting that you have skipped a step here, cut a corner there, so on and so forth. Yet again resulting in an error when you least except it.

  3. If something can go wrong, it will at some point do.
    This is a universal rule (another variant). Don't try ignoring it. The only thing is to make sure that nothing can go wrong. However even the best developers cannot avoid all errors therefore contain the error so it will not affect the outside world and implement a graceful fallback error handling routine.

  4. Never implement bad exception handling. Like the Ostrich-algorithm, where you put your head in the ground and pretend that nothing has happened.
    This is a common error handling that I have seen in various places, where the developer knows that something can go wrong, but is too lazy to implement a descent error handling logic. Thereby resulting in a possible unstable program. This happened to me once when another developer in my team made an empty try catch statement around a database call. When the call to the database failed - and it did happen from time to time - the code simply just continued like nothing had happened, resulting in that the database data became invalid. So I had to spend 2 full days debugging the entire code in order to find out why the program was unstable and not knowing where the error prune part was hiding.

  5. Know your events or you program will fail.
    This is one of the most important things you can do when coding in object oriented languages. Know in what order things happen in. I have seen a lot of developers writing a lot of bad code in ASP.NET because they simply haven't allowed themselves the time to study how a Page lifecycle works.

  6. Errors usually appears where you least expect them to.
    This is another law of the Universe. You might as well accept it!
    If you ever think a certain situation will never occur, you are properly wrong. I have heard this so many times "This will never happen… yada yada yada" – but trust me, it will! So always implement at least a minimal form of error handling.

  7. Users come from the dark side and they got errors with them.
    No developer can foresee every possible outcome of a program and users have the tendency to pick out the situations that you had never have thought of. So always think of in general error handling, so you can say to yourself… "Whatever happens, I have covered it."

  8. Unit test... unit what?
    This is an important thing to remember, especially when doing a lot of backend logic. There has been written a lot of topics on this subject and therefore I will not cover it here.

  9. Keep it simple! However this does not apply for the female developers, they are able to multi task!
    Male developers tend to develop programs with their forehead. This puts a constraint on how many of lines of code that they can handle simultaneously. Males like giant things, but giant methods are a bad thing. It is easy to lose overview of what is going on in the method with too many lines of code and therefore the possibility for errors sneaking in is greater. Keep your methods at a minimum, even if they are just used once in a call from one other method.

  10. Always include a dead-man switch in a While loop, if it potentially can loop forever.
    All developers in world has made this one at least once in their lifetime. Creating a While statement but forgets that they can potentially run forever and it stalls the process. So if there is even the slightest chance that a While statement can loop beyond its intention, introduce a dead-man switch. A simple counter that can only count to a certain amount before ending the while loop.

This more or less concludes my 10 commandments. Read it, learn from it and hopefully improve on it.

Monday, April 13, 2009

WSPBuilder documentation

I know that the documentation on using the WSPBuilder hasn't been fulfilling to say it nicely, but that's the way it is.

The good thing is that other people have been nice and done some work on this. This is what I have found so far (in random order), sorry if have forgot someone.

WSPBuilder - Walkthrough of the Visual Studio Add-in
http://www.zimmergren.net/archive/2009/04/08/wspbuilder-walkthrough-of-the-visual-studio-add-in.aspx

WSS: Development - Quick Start with WSPBuilder
http://rasor.wordpress.com/2008/10/12/wss-dev-quickstart/

WSS Dev: WSPBuilder Templates
http://rasor.wordpress.com/2008/10/12/wss-dev-quickstart/

WSS Dev: HowTo debug a WebPart
http://rasor.wordpress.com/2008/10/24/wss-howto-debug-a-webpart/

Change the WSPBuilder DeploymentTarget to WebApplication
http://blog.mastykarz.nl/change-wspbuilder-deploymenttarget-webapplication/

Intro to WSPBuilder
http://www.michaelbowersox.com/2009/01/18/intro-to-wspbuilder/

WSPBuilder Folder Structure
http://www.michaelbowersox.com/2009/01/28/wspbuilder-folder-structure/

Developing SharePoint Solutions in Visual Studio
http://greggalipeau.wordpress.com/2008/05/18/developing-sharepoint-solutions-in-visual-studio/

TFS Build and WSPBuilder
http://alex-tfs.blogspot.com/2009/01/tfs-build-and-wspbuilder.html

How to get TFS to automate your WSP builds with WSPBuilder
http://pointstoshare.spaces.live.com/Blog/cns%21AEC42F315B4528B0%213290.entry

The WSPBuilser Manual
http://wspbuilder.codeplex.com/SourceControl/changeset/view/33013#166101

My Blog.
http://keutmann.blogspot.com/2008/02/visual-studio-addin-and-templates-for.html

New! (2009/08/02)

Creating a code-only webpart and deploying as a feature
http://www.sharepointsean.com/articles/Pages/CreatingaCode-Onlywebpartanddeployingasafeature.aspx

Please comment with more links if you know one.

Friday, April 10, 2009

WSPBuilder - Walkthrough of the Visual Studio Add-in

I know that there are not much documentation on how to use WSPBuilder in the install package, but my good friend Tobias Zimmergren have written a great post on SharePoint development with WSPBuilder Extensions. Check it out. http://www.zimmergren.net/archive/2009/04/08/wspbuilder-walkthrough-of-the-visual-studio-add-in.aspx

WSPBuilder Extensions 1.0.5

This version of WSPBuilder Extensions 1.0.5 now fully supports development on an x64 bit systems and Windows Server 2008.

Installs correct CABLIB.DLL for x64 systems. (No need for manually installing)
"Copy to 12 hive" function now works on x64 systems.
Support for IIS7
Minor bug fix for "Recycle App Pools"
Supports VisualBasic Project/Item templates. (Thanks to Chip Sockwell)
wspbuilder.exe is included in this package.

Install notes.:
Be sure to uninstall the old version of WSPBuilder Extensions before installing the new version.

Happy SharePoint coding folks

/keutmann

Thursday, March 12, 2009

Visual Basic Project/Item template support in WSPBuilder Extensions 1.0.4

Thanks to Chip Sockwell and his work on converting the C# templates to Visual Basic. You are now able to create Visual Basic projects with WSPBuilder templates in Visual Studio.

However if you are only using C#, you do not need to install the new version (1.0.4).

Get it here: WSPBuilder.com

Cheers!
/keutmann

Thursday, February 05, 2009

SharePoint Manager 2007 ver 0.9.9.0205

I have done some work on SPM2007 and implemented a new language Swedish. (Thanks to Andreas Kviby for the translation)

Ver: 0.9.9.0205-------------------
- Warning on deletion has now been implemented.
- Icons for nodes updated.
- Dutch and Swedish languages implemented.
- Groups and Roles on the Site is now browsable.

Get it on codeplex.

Have fun :)

Friday, January 30, 2009

SharePoint MVP

Oh .. by the way.. I have become a SharePoint MVP.

Cheers!

Sunday, October 12, 2008

Get SharePoint To Validate

My good friend Anders Dissing has released this awesome project on codeplex.
This project is all about making SharePoint/MOSS XHTML compliant.

· Get SharePoint 2007 to validate according to W3C XHTML 1.0 Strict.
· Google-optimize SharePoint to gain the best search ranking.
· Enhanced accessibility.
· Makes it possible for SharePoint to follow the American regulation 508 and the Danish regulation based on WCAG AA.
· Better control over the HTML output of SharePoint, to ease the frontend development process.

Project site:
http://www.codeplex.com/GSPTV

Demo site:
http://getsharepointtovalidate.com/

Friday, October 03, 2008

SharePoint Manager 2007 ver. 0.9.8.1002

New version of SPM2007 has been released on codeplex.

Ver: 0.9.8.1002
-------------------
  • Feature collection now uses try catch on invalid features.
  • Title used to show names of JobDefinitions.
  • SPEventReceiverDefinition implemented. EventReceivers are now browsable.

/Happy SharePoint object model browsing :o)

Saturday, August 30, 2008

WSPBuilder (with local config file support)

Thanks to Tom Clarkson for adding this feature to WSPBuilder, its now able to load a wspbuilder.exe.config file from a local project. This enables project specific arguments to WSPBuilder when building from Visual Studio.
WSPBuilder will first look for the general config file, then the local project and last the command line arguments.

Wednesday, August 27, 2008

0.9.8.0822 is a memory eating monster

Get the new version 0.9.8.0827 from codeplex

The previous version of WSPBuilder 0.9.8.0822 was a memory eating monster, now the memory foot print has been greatly reduced to a more acceptable level.

The reason for this was that Mono.Cecil uses a lot of memory to load the assemblies. Therefore when loading reference assemblies and base class assemblies like System.Web the memory consumption exploded. Now every assembly gets unloaded right after it has been used.

Friday, August 22, 2008

The history of WSPBuilder

WSPBuilder (June 2007)
In the beginning of 2007 I was tired of writing the wsp manifest.xml file and defining the DDF file by hand. I really needed a tool to auto generate this. I tried one of the first tools on the internet that someone had made (I have forgotten where),however it was written in VBscript and only implemented some very basic functionality. But it made me discover that the structure of the wsp file is simply a reflection of what goes into the 12 hive. Therefore it was clear to me that the next step was to simply make it a full blown C# project. Still I needed to be sure to cover all of the possibilities that wsp schema had to offer. Luckily Microsoft provides a xml schema definition for the manifest.xml file. This made it possible to auto generate a C# class library that would serialize into a manifest.xml file. Then the only thing that I had to do now was to fill in the code and serialize the objects. But I was not home yet, I needed something to create the CAB file (WSP). I was able to choose from the makecab.exe application provided by Microsoft or use the CabLib.dll project created by Elmue. In the spirit of GPL and for full control of the Cab file creation I went for the Elmue project.

Deployment (August 2007)
Here the power of the GPL license really comes into effect. Chris Doty created the deployment part of WSPBuilder and submitted it to me. First it was made as a independent console application WSPDeployer.exe and later on it was merged into the WSPBuilder application.

WSPBuilder Extensions (January 2008)
Tom Clarkson really did a big contribution here. He basically created the WSPBuilder Extensions project with Visual Studio project and item templates and an Visual Studio Addin with a MSI install program with it. After some minor modification the first version of WSPBuilder Extensions was born. In the following versions the Extensions has been improved and the Visual Studio Addin has been rewritten to a more professional look and the functionality extended.

Mono.Cecil (may 2008)
The WSPBuilder was having some issues with reflection on assemblies in order to be able to create the SafeControls tags in the manifest file. If an assembly was located in the Global Assembly Cache, the .NET framework would always pick up this assembly and not the newly build assembly from the project, therefore resulting in a possible incorrect manifest file. Also assembly references was a big problem for many users of WSPBuilder. This was because the users had the tendency to put reference assemblies other places on their system and because of this the .NET framework was not able to find them. With the Mono.Cecil project written by Jb Evain, WSPBuilder is now able to load the assemblies even that a copy existed in GAC and reflect on them without having to load all of the referenced assemblies.

Community
I want to thank all the people that have helped to improve the WSPBuilder product by using, testing and reporting bugs. Microsoft for providing the codeplex.com site that enables you to use team foundation source control with your Visual Studio Environment and also for hosting the WSPBuilder project.

Conclusion
Even that WSPBuilder has not reached its full first version yet, it’s nearly completed. There are still some bugs to be fixed and documentation to be made, but overall it should implement every possible scenario that you are able to make with the Windows SharePoint Package (WSP).

WSPBuilder.exe version 0.9.8.0822 x86

New version of WSPBuilder has been released on codeplex.

This time some major issues with SecurityAttibutes reflection has been solved and also reflection on assemblies to created the relevant SafeControl tags has been implemented. Now the WSPBuilder with the Mono.Cecil project, is better able to create a correct manifest.xml than it was with the normal .NET assembly reflection. The only downfall is that WSPBuilder is a little bit slower than before, but it should not be notable. Also the Assembly Element tags has been moved to the top of the manifest.xml file in order to ensure that assemblies is deployed first, this seems to solve a problem in rare occasions.

Change list:
  • Assembly element tags in the manifest.xml is placed in the top of the manifest.xml file.
  • Resolvement of assemblies is now supported with Mono.Cecil in order to create relevant SafeControl tags. Use the -DLLRefencePath argument to resolve referenced assemblies.
  • Bug fixed where the 80\WPResources was not included-.
  • Bug fixed where the security attributes was not reflected correctly.

Take care :o)

Tuesday, July 22, 2008

WSPBuilder Extensions 1.0.3 - Visual Studio Addin

A new version of WSPBuilder Extensions 1.0.3 for Visual Studio has been released on codeplex.

  • Now uses the WSPBuilder 0.9.8.0408 version.
  • The Addin has been totally rewritten and should now work properly. A number of bugs fixed.
  • The WSPBuilder menu is now available from the Tools menu.
  • The shortcut key bug now fixed.
  • A new command "Copy to GAC" Added.
  • You are now able to use “Copy to 12 hive” on project, selected folder or files under the 12 hive folder.
  • The WebPart Item template has been updated.

Note: To use the WSPBuilder Extensions on a x64 system, replace the CABLIB.DLL x86 version, found in “Program Files\WSPTools” folder and Global Assembly Cache, with a CABLIB.DLL x64 version. Look for the CABLIB.DLL x64 version in a previous x64 release of WSPBuilder.

Wednesday, May 21, 2008

PublishingFeatureHandler

Feature ID 22A9EF51-737B-4ff2-9346-694633FE4416

In lack of documentation on this feature and the properties it contains, I did some reflection on the class. But the inner workings of the class is obfuscated and therefore I was only able to get the properties declared as constants. I have not tested all of the properties, so I actually do not know if they will work.

Properties in the PublishingFeatureHandler feature that you are enable to set in the ONET.XML

Like this...

<!-- Publishing feature -->
<Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
<Properties xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Key="WelcomePageUrl" Value="$Resources:cmscore,List_Pages_UrlName;/Default.aspx" />
<Property Key="PagesListUrl" Value=""/>
<Property Key="AvailableWebTemplates" Value=""/>
<Property Key="AvailablePageLayouts" Value=""/>
<Property Key="SimplePublishing" Value="true" />
...
</Properties>
</Feature>

PublishingFeatureHandler properties

NameTypeDefault value Simple publishingDefault value Complex publishingDescription
AlternateCssUrlstringnullnull

Add the css file to the application pages resided in the layouts folder.
Syntax format: ~SiteCollection/Style Library/mycustom.css

AvailablePageLayoutsstringnullnull

Syntax format: ~SiteCollection/<pagelayout path1>:~SiteCollection/<pagelayout path2>:~SiteCollection/<pagelayout path3>Example..:
~SiteCollection/_catalogs/masterpage/mypage1.aspx: ~SiteCollection/_catalogs/masterpage/mypage2.aspx: ~SiteCollection/_catalogs/masterpage/mypage3.aspx
Use the : colon as the separator.

AvailableWebTemplatesstringnullnull

AvailableWebTemplates Key Format is:LCID-[sitetemplatename][#sitetemplatenumber];LCID-[sitetemplatename][#sitetemplatenumber];LCID-[sitetemplatename][#sitetemplatenumber]
Example: 1033-BLANKINTERNET#1;1049- BLANKINTERNET #1;*- BLANKINTERNET #2;*-BLANKINTERNET#2

ChromeMasterUrlstringnullnullSyntax format:
~SiteCollection/_catalogs/masterpage/mycustom.master
EnableApprovalWorkflowOnDocumentsboolfalsetrue
EnableApprovalWorkflowOnImagesboolfalsetrue
EnableApprovalWorkflowOnPagesboolfalsetrue
EnableModerationOnDocumentsboolfalsetrue
EnableModerationOnImagesboolfalsetrue
EnableModerationOnPagesboolfalsetrue
EnableSchedulingOnDocumentsboolfalsetrue
EnableSchedulingOnImagesboolfalsetrue
EnableSchedulingOnPagesboolfalsetrue
MigrationOverrideboolfalsefalse
PagesListUrlstringnullnull
RequireCheckoutOnDocumentsboolfalsetrue
RequireCheckoutOnImagesboolfalsetrue
RequireCheckoutOnPagesboolfalsetrue
SimplePublishingboolIf not defined, the default value is true. Specifies the setup with simple or complex publishing configurations.

VersioningOnDocuments

VersioningSettingsMajorMajorAndMinor

Possible values for VersioningSettings is: Major, MajorAndMinor, None

VersioningOnImagesVersioningSettingsMajorMajorAndMinor
VersioningOnPagesVersioningSettingsMajorAndMinorMajorAndMinor
WelcomePageUrlstringnullnull

Defines the page that will act as the startup page.

Example: $Resources:cmscore,List_Pages_UrlName;/default.aspx


Friday, April 11, 2008

WSPBuilder.exe version 0.9.8.0408 (experimental)

I finally got around to implement the Mono.Cecil library into WSPBuilder. I hope this will solve some of the resolvment issues with assembly reflection that was with Assembly.LoadFrom. Further more that Global Assembly Cache is ignored when loading assemblies. Also security reflection (CAS) of the assemblies have been improved and should now be complete. The -CustomCas parameter still needs improvement and may be rewritten.


WSPBuilder.exe version 0.9.8.0408 (experimental)
Note! This version is a complete rewrite of the assembly reflection done in WSPBuilder and therefore the experimental status.
----------------------
Assembly reflection is now done with the Mono.Cecil project. This enables the WSPBuilder to reflect on assemblies without having to load all depending assemblies.
-DLLReferencePath are now obsolete, because there is no need for load depending assemblies, but it still may be used in the future.
The WSPBuilder are not able to detect if a control is inherited from a WebControl, therefore there may be more safecontrols tags in the manifest. This is because that depending assemblies are not loaded.
Code Access Security declaration in the manifest.xml have been improved for DLLs in the 80\Bin folder.
The "assembly is already in the GAC bug" have been solved. WSPBuilder now only loads assemblies from the project folder and do not care about the assemblies in the Global Assembly Cache.
-PermissionSetLevel do NOT support Unrestricted PermissionSet. Because its not possible to add this to the manifest.xml.


Note that there are two versions on codeplex.
Different versions:
WSPBuilder Extensions ver. 1.0.1 - Visual Studio Addin, wspbuilder.exe 0.9.8.0206 is included in this package.
WSPBuilder.exe version 0.9.8.0408 (experimental) - Only exe file and libraries.

The x64 version of WSPBuilder.exe will be added to codeplex soon.

Thats it for today.

Wednesday, February 06, 2008

Visual Studio Addin and Templates for WSPBuilder

WSPBuilder Extensions ver. 1.0.0 (RC)

Now the first version of WSPBuilder Extensions is ready. It has been a long road up the hill and a lot of hours spend at home after my day work to get this first version done.

I want to specially thank Tom Clarkson for doing the Visual Studio Templates, he has done an awesome work on creating the templates and I would never have been able to finish it without him.

It has also been great that the community contributes to the WSPBuilder project with error reports and suggestions for new features.

The WSPBuilder Extensions ver. 1.0.0 (RC) supports Visual Studio ver. 2005 and 2008 and comes in a nice MSI install package.

The WSPBuilder.exe contains a lot of functionality that I simply did not have time to implement into Visual Studio. Also WSPBuilder.exe does not read the Visual Studio project file but still relies on the project folder to build the WSP file. Therefore you may not see the file in Visual Studio because it’s excluded from the project file, but it still gets build into the WSP file.

After install start your Visual Studio, and create a new project.



Now create a new SharePoint Feature.



Finally build the project and deploy it.



Try it out and tell me what you think.

Take care.

/keutmann

Thursday, December 27, 2007

WSPBuilder 0.9.7.1227. From Mono.Cecil to LoadFrom

It have been a long way to the next version. I have been looking into other ways to reflect on Assemblies, but I ended up using the technique I was using from the start however just with better assembly resolvement.

My goal was to avoid to resolve referenced assemblies when getting the class types from a loaded assembly.

I started looking into Mono.Cecil that looked very promising at first, but there was very little documentation on it and little on how to use it on the Internet. However I was successful nearly to the end but it stranded on SecurityAttributes. It was not able to read them when the attributes had parameters.

Now I turned my focus on to the Assembly.ReflectionOnlyLoadFrom method. This also stranded because it was not able to read the SecurityAttributes (this is actually by design from Microsoft).

So now I had no other options than go back to Assembly.LoadFrom method. I have then improved the resolvement of assemblies, so there will be a good error message when a referenced assembly fails to resolve. Then use the -DLLReferencePath argument to resolve the assembly.

Download: WSPBuilder

Versions
---------------------
0.9.7.1227
-BuildSolution is now fixed. This enables you to build multiple projects into one WSP file.
Multiple files with the same name (location) in CAB file have been solved.
Assembly resolve now outputs better error description - bin\debug and bin\release is now supported.
Bug fixed with ProjectDLLPath argument.
Feature warning corrected.

Wednesday, December 12, 2007

SharePoint Manager 2007 added to codeplex

I finally got around to release the SharePoint Manager 2007 with source code on codeplex.

You can get it here http://www.codeplex.com/spm

My focus is currently on WSPBuilder, so I will not be doing much on this project. However if you have any changes or will like to develop on this project, please contact me.