Blogger :
MSDN Blogs
All posts :
All posts by MSDN Blogs
Category :
SAP Portal
Blogged date : 2008 Feb 24
The first thing you realize when playing with Site Definitions is that "IISRESET" is your next best friend. However, if you plan on deleting your old site collection and create a new one (to test a RootWeb / Site Collection site definition), it's very long to re-open up the Central Administration and do it through the interface since you'll have to reload both the CA and your web site.
Since I'm no master of Site Definitions, I'm still doing a lot of resetting because I like to understand each portion of the site definition. I started by creating a small DOS Batch File (CMD) that was copying my xml, deleting the site collection and recreating it through STSADM. If no error is found, I start Internet Explorer on my URL. Basically, I can drag this CMD file on my Quick Launch, click it, go take a coffee and when I come back, the site will be loaded (unless I made a mistake in the XML!).
Also, I'm using Visual Studio to edit Site Definitions since I am storing them in Team Foundation Server. Why VS? Well since playing with Site Definitions requires that you open up a few XML (the WebTemp*, the onet, the feature.xml that you are linking, etc.), it's nice to have a single GUI with all the editing tools and structure. Of course, the Site Definition Viewer is practical for any Site Definitions, but it's not an editor so VS was my choice.
If you create it, you end up with a structure like this (more or less) picture :
As you can see, you may have a custom web.config as well as RESX files to put in App_GlobalResources. Of course, when you deploy to your production server, you won't use these scripts and rather a WSP that will apply web.config modifications through SPWebConfigModification. This script is merely to have a quick and dirty copy for development box before you are ready to create Builds.
In the root, you can see 4 scripts :
- Variables.cmd contains all the required variables to function. You should check that it matches your environment before running the other script.
- CopyFiles.cmd will copy your 12 hive, your web site folder (dubbed 80), and your RESX files before any other scripts is ran
- CreateSiteDefinition.cmd will call CopyFiles and then delete + create a site collection with the variables defined in Variables.cmd
- InstallFeature.cmd is simply a helper that will copy your 12 hive and then install -FORCE all features in the script. If you add a feature, add the command line there.
I'm still working on it and plan to add functionalities such as "CreateWeb" list from an Excel spreadsheet. That basically replace most of my "SiteBuilder" STSADM extension (except for creating content pages!) and simply runs a series of STSADM -o CreateWeb commands with an input file that you edit in Excel. Very neat but it's unfinished so I'll post the update later. You can download the current version here:
Here's the included files:
Variables.cmd
1: @ECHO OFF
2: IF "%variables%"=="true" GOTO END
3:
4: @SET separator=*******************************************************************************
5:
6: @ECHO %separator%
7: @ECHO Creating variables
8: @ECHO %separator%
9:
10: :VARIABLES
11: @SET variables=true
12: @SET stsadm="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm"
13: @SET lcid=1033
14: @SET description="Test Custom Portal"
15: @SET title="Test Custom Portal"
16:
17: @SET owneremail=%USERNAME%@%USERDNSDOMAIN%
18: @SET user=%USERDOMAIN%\%USERNAME%
19: @SET sitetemplate="MyCustomSiteDefinition#0"
20: @SET url=http://%COMPUTERNAME%:80
21: @SET hive12="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12"
22: @SET wwwsites="c:\inetpub\wwwroot\wss\VirtualDirectories\80"
23:
24: :END
CopyFiles.cmd
1: @CALL Variables.cmd
2:
3: @ECHO %separator%
4: @ECHO Copying features and site definitions to 12 hive
5: @ECHO %separator%
6:
7: CD 12
8: XCOPY /y /s *.* %hive12% > nul
9:
10:
11: @ECHO %separator%
12: @ECHO Copying Web.config and resources files
13: @ECHO %separator%
14:
15: CD ../80
16: XCOPY /y web.config %wwwsites% > nul
17:
18: CD ../App_GlobalResources
19: XCOPY /y *.* %wwwsites% > nul
20:
21: IISRESET
CreateSiteDefinition.cmd
1: @CALL Variables.cmd
2: @CALL CopyFiles.cmd
3:
4: @ECHO %separator%
5: @ECHO Deleting Site Collection + Resetting IIS
6: @ECHO %separator%
7: %stsadm% -o deletesite -url %url% -deleteadaccounts false
8:
9: @ECHO %separator%
10: @ECHO Creating Site Collection
11: @ECHO %separator%
12: %stsadm% -o createsite -url %url% -owneremail %owneremail% -ownerlogin %user% -lcid %lcid% -sitetemplate %sitetemplate% -title %title% -description %description%
13:
14: IF ERRORLEVEL 0 GOTO IE
15: @ECHO %separator%
16: @ECHO Error while deleting or creating Site Collection
17: @ECHO %separator%
18: pause
19: GOTO END
20: