Showing posts with label Deployment. Show all posts
Showing posts with label Deployment. Show all posts

Friday, 15 October 2010

Must-know SharePoint debugging tips

This post is a follow-on to my Must-Know Visual Studio debugging tips article; I'm separating out my SharePoint debugging tips focused on list, feature, and solution deployment that don't relate to Visual Studio.

Here you go:

  • Try activating your feature without the –force attribute; you'll likely need to deactivate the feature first
  • Try uninstalling and reinstalling the feature
  • If something stuck and rebooting seems to clear some kind of cache deep inside SharePoint, stop IIS and restart the various SharePoint Windows services

@echo off
@echo Stopping services...
iisreset /stop /noforce
net stop "Windows SharePoint Services Timer"
net stop "Windows SharePoint Services Administration"
net stop "Office SharePoint Server Search"
net stop "Windows SharePoint Services Search"
net stop "Windows SharePoint Services Tracing"
@echo Starting services...
net start "Windows SharePoint Services Tracing"
net start "Windows SharePoint Services Search"
net start "Office SharePoint Server Search"
net start "Windows SharePoint Services Administration"
net start "Windows SharePoint Services Timer"
iisreset /start
@pause

  • Create a new list from your list definition (or at least, a new list item)
  • Rebuild your solution and redeploy
If you found this post helpful, please support my advertisers.

Saturday, 19 June 2010

How to add a web project item to a class library

This is an old trick but I've found myself hunting for it repeatedly as of late…

If your current visual studio project doesn't provide the option to add a web user control, web page, etc (perhaps because the project is a class library or a WSPBuilder project), you can easily tweak the project file enable support for these templates.

To do so:

  • Unload the project (right-click the project in Solution Explorer and select Unload Project from the context menu)
  • Edit the .csproj file (right-click the project in Solution Explorer and select Edit MyProj.csproj from the context menu)
  • Locate the ProjectTypeGuids element and add a magic project type GUID to beginning of the list: {349c5851-65df-11da-9384-00065b846f21};
  • Save your changes and reload the project (right-click and Reload Project)

When you're done editing the .csproj file it should look like this:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Now you can add user controls and whatnot to your heart's content!

Update Feb 2011: When I last had to this in VS2010, things were a bit different. The class library contained a ProjectGuid element but no ProjectTypeGuids. According to the post I link to above, a ProjectTypeGuids element can be added below the ProjectGuid so I pasted in the above. Although VS "helped out" by rejigging the XML for me and modifying the GUID when I subsequently inspected it, the project allows me to add web items.

Each class library seems to get a different (unique) ProjectGuid value so I'm not sure how adding the child ProjectTypeGuids element (which was subsequently removed by VS) actually worked… but it did ;-)

Monday, 19 April 2010

No parameterless constructor defined for this object when creating a new page

With everything working admirably in development I was greeted with the below error message when attempting to create a new page after today’s fresh deploy to UAT (and eventually prod, where I gave up):

Error No parameterless constructor defined for this object

No fun but luckily the problem was easily isolated and a work around arrived at—although I have yet to unearth the root cause.

By way of more detail, I was attempting to create a new page instance in a new sub site using a branded master page and page layout. This isn’t normally a problem and seems to be limited to this master page/layout combo as I can successfully create page instances in the same sub site using another layout known to be good. The problematic page layout contains a single rich text field and webpartzone but, unlike other posts discussing the same error message, the <zonetemplate> element is empty and I’m not attempting to deploy web parts to the page using the AllUsersWebPart crappiness. I just want my basic page!!

Most of the suggestions out there for resolving the above error lead you to the web part editor maintenance screen (see below) where you’ll find one or more ErrorWebParts, which can then be deleted. The problem with this approach is maintaining the page’s web parts requires the page layout to be checked out and that customises the layout, meaning future feature-based deployments of that layout won’t “take”. Of course, my layout isn’t supposed to have any web parts so go figure where the single mysterious ErrorWebPart originates… there seems to be a (related?) issue accessing web part programmatically in which ErrorWebParts objects are returned instead so I wonder if this is a different web part than how it’s represented…

Others suggest redeploying the layout after deleting it from the gallery but that didn’t work in my case.

In the end, I created a page from a different layout using the same content type as my desired page and then changing the layout. All fine from there but not at all usable—luckily this was for a short-lived campaign site.

How to open a page layout in web part maintenance mode

Just as a page instance can have web parts, a page layout can also have web parts. To manage those web parts, check out the layout within the Master Page Gallery, and click View Properties from the context menu. Next, edit the item and click the ‘Open Web Part Page in maintenance view’ link at the bottom of the page.

Alternatively, you can substitute your page layout in this URL:

http://<server>/_catalogs/masterpage/<page layout name>.aspx?contents=1

Tuesday, 30 March 2010

Building SharePoint Solutions with TFS Build 2008

After deploying Team Foundation Server 2008 in late 2008, the project’s second phase was intended to implement Team Build to automate builds and establish a continuous integration process for our key projects. At the time, the initial investigation work determined this to be all too hard, which is unfortunate because I’ve been doing the builds for our team ever since!

With our first-stab process templates and first-stab branch structure now being revised, and with Team System 2010 due any day now, I decided to review what “too hard” really meant and see for myself what it would take to get the 2008 build server running. In our case, we’re not only dealing with SharePoint builds and the need to output a .wsp/.cab solution file but a VS solution structure first established in 2006. One of our projects also builds a deployment (.msi) file.

Although I have yet to get the solutions proper tweaked and loaded up, I have got a relatively simple MSBuild-based SharePoint solution building, batch file post-build events and all. This post is a summary of my notes and findings from my efforts to get this working.

Andrew Connell has a detailed post on how to get MSBuild playing with MakeCab.exe, so I’d recommend starting there if you don’t have the MSBuild bits in place already. From that point I largely followed Jeremy Jameson’s advice to get the .targets and .ddf files working across desktop builds and TFS Build. For more information about MakeCab and DDF files, I highly recommend you read the MakeCab documentation linked from my earlier post.

Relative Paths

Perhaps most critically, note Visual Studio and TFS will build your source from different locations. This rules out using absolute paths in any of your scripts or things will break; you also need to be very careful with relative paths because even that old stalwart, \bin, doesn’t exist in the TFS Build environment (it instead uses \binaries).

What this means is relative paths are acceptable but you do need to suck them out of the environment variables/macros set by Visual Studio/Team Build—primarily $(OutDir) or whatever works best for you.

OutDir Cleanup

$(OutDir) may include spaces and will likely include a trailing slash, which needs to be cleaned up by adding quotes to avoid issues with spaces and removing the trailing slash before it can be supplied to MakeCab. I added this to the PropertyGroup element in my .targets file:

<QuotedOutDir>"$(OutDir)"</QuotedOutDir>
<QuotedOutDir Condition="HasTrailingSlash($(OutDir))">"$(OutDir)."</QuotedOutDir>

The property is subsequently supplied in the target:

<Exec Command="$(MakeCabPath) /F $(DDFName) /D CabinetNameTemplate=$(CabinetOutputFileName) /D Out_Dir=$(QuotedOutDir)" />

Remember, any changes to the .targets file will not be detected until the .csproj file is unloaded and reloaded (right-click in Visual Studio).

DDF and .Option Explicit

The Out_Dir parameter I supply to MakeCab (or rather the .ddf file, more precisely) is a custom variable unknown to MakeCab. With .Option Explicit enabled, you would normally be required to include a statement like this:

.define Out_Dir=

My understanding is MakeCab doesn’t support this, however, and .Option Explicit must therefore be turned off or you'll end up with an error like this:

ERROR: Option Explicit and variable not defined: OUT_DIR

Reference Other Projects and .Set SourceDir

To get the assemblies and debug symbols from the bin directories in your other projects to the deployment project, it’s easiest to to have the deployment project reference those projects; the DLLs and pdb files will then be copied to the deployment project’s bin directory—which is also the value of $(OutDir).

Instead of then referencing these files using a long path in the .ddf, they can now be referenced simply by name. You’ll first need to configure the SourceDir in the DDF, however before resetting it for the remaining files:

.Set SourceDir=%Out_Dir%
MyControls.dll
MyControls.pdb
.Set SourceDir=

Dummy Code File

I make use of a dedicated class library project responsible for wrangling the MSBuild bits, post-build events, and to otherwise contain all the SharePoint solution and feature bits. As a class library this project wants to compile and output an assembly but with no source code in the project, TFS Build will throw up a compiler error (everything will work fine on the desktop, however):

CSC(0,0): error CS2008: No inputs specified

To work around this, add an empty .cs file to the project (it’s a hack).

Long File Paths

Windows’ own maximum path length rules will kick in once you hit 259 or 260 characters. If you’re already working in a deep branch with a matching file system path structure, Team Build will likely cause you problems when it starts shifting sources into is own working directories below C:\Documents and Settings\{service}\Local Settings\Temp\. Consider the changes suggested by Aaron Hallberg to work around this problem.

Good luck!

Manifest.xml and Root Paths

The Bonobo Journal has a nice little table detailing where the files in your solution manifest will end up once deployed to the SharePoint root. I’ve taken the liberty of reproducing the table here and expanding it for future reference:

Manifest Element Location’s Root
ApplicationResourceFile 12\Resources
Assembly Web application bin or GAC
DwpFile Virtual directory\wpcatalog
FeatureManifest 12\TEMPLATE\FEATURES
Resource 12\TEMPLATE\FEATURES
ResourceFile 12\TEMPLATE\FEATURES
RootFile 12
SiteDefinitionManifest 12\TEMPLATE\SiteTemplates
TemplateFile 12\TEMPLATE
WebTempFile 12\TEMPLATE