다음을 통해 공유


(March Update) Site Definition developer helper scripts

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 :

SiteDefinitionVSStructure

 

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.

 

**March Update** :

  • I added more scripts :
    • CreateWebs.cmd (to create a series of web, explained here)
    • DeleteWeb.cmd (to delete webs (in order to launch another creation))
    • GAC.cmd (to add DLLs to the GAC)
    • Go.cmd (to have a menu of options)

 

The previous scripts have been updated as well and are cleaner.  Here's a screenshot of the Go command:

HelperScript-Go

**/End March Update**

 

 

I'm still working on it and plan to add functionalities such as "CreateWeb" list from an Excel spreadsheet **March Update** : read the post here for the CreateWeb **/March Update**.   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.  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=https://%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: @SET gacutil="E:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil"
   24:  
   25: :END

 

CopyFiles.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5:  
    6: @ECHO %separator%
    7: @ECHO Copying features and site definitions to 12 hive
    8: @ECHO %separator%
    9:  
   10: CD 12
   11: XCOPY /y /s *.* %hive12% > nul
   12:  
   13: @ECHO %separator%
   14: @ECHO Copying Web.config and resources files
   15: @ECHO %separator%
   16:  
   17: CD ..\80
   18: XCOPY /y web.config %wwwsites% > nul
   19:  
   20: CD ..\App_GlobalResources
   21: XCOPY /y *.* %wwwsites%\App_GlobalResources > nul
   22:  
   23:  
   24: IISRESET
   25: @ECHO.

 

CreateSiteDefinition.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5: @CALL CopyFiles.cmd
    6:  
    7: @ECHO %separator%
    8: @ECHO Deleting Site Collection
    9: @ECHO %separator%
   10: %stsadm% -o deletesite -url %url% -deleteadaccounts false
   11:  
   12: @ECHO %separator%
   13: @ECHO Creating Site Collection
   14: @ECHO %separator%
   15: %stsadm% -o createsite -url %url% -owneremail %owneremail% -ownerlogin %user% -lcid %lcid% -sitetemplate %sitetemplate% -title %title% -description %description%
   16:  
   17: IF ERRORLEVEL 0 GOTO IE
   18: @ECHO %separator%
   19: @ECHO Error while deleting or creating Site Collection
   20: @ECHO %separator%
   21: SET ERRORLEVEL=-1
   22: pause
   23: GOTO:eof
   24:  
   25: :IE
   26: @ECHO %separator%
   27: @ECHO Operation completed
   28: @ECHO %separator%
   29:  
   30: IF NOT "%1"=="noie" start iexplore %url%

 

InstallFeature.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5: @CALL CopyFiles.cmd
    6: @CALL GAC.cmd
    7:  
    8: @ECHO.
    9: @ECHO %separator%
   10: @ECHO Forcing features installation
   11: @ECHO %separator%
   12: @ECHO.
   13:  
   14: @ECHO --[ Installing MyCustomFeature ]----------------------------------
   15: %stsadm% -o installfeature -name MyCustomFeature -force
   16: IF NOT ERRORLEVEL 0 GOTO PAUSE
   17:  
   18:  
   19: :PAUSE
   20: @ECHO %separator%
   21: @ECHO Error while installing last feature
   22: @ECHO %separator%
   23: PAUSE

 

CreateWebs.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5:  
    6: @ECHO %separator%
    7: @ECHO Create Website Structure and Content.
    8: @ECHO %separator%
    9:  
   10: :CREATEWEBS
   11: @ECHO:
   12: @ECHO %separator%
   13: @ECHO Create Site Structure
   14: @ECHO %separator%
   15: @ECHO.
   16:  
   17: FOR /F "eol=; tokens=1,2,3,4 delims=    " %%i IN (Data/CreateWebs.txt) DO (
   18:     @ECHO ----[ Creating "%%i" ]--
   19:     %stsadm% -o createweb -url %url%%%i -sitetemplate %%j -title "%%k" -lcid %%l
   20: )
   21:  
   22:  
   23: :IE
   24: @ECHO %separator%
   25: @ECHO Operation completed
   26: @ECHO %separator%
   27:  
   28: IF NOT "%1"=="noie" start iexplore %url%/fr/fcdq/

 

DeleteWebs.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5:  
    6: @ECHO %separator%
    7: @ECHO Delete Website Structure and Content.
    8: @ECHO %separator%
    9: @ECHO.
   10:  
   11: %stsadm% -o deletesubwebs -url %url%/fr -recurse true
   12: %stsadm% -o deletesubwebs -url %url%/en -recurse true
   13:  
   14: :IE
   15: @ECHO %separator%
   16: @ECHO Operation completed
   17: @ECHO %separator%

 

GAC.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5:  
    6: @ECHO %separator%
    7: @ECHO GAC Util
    8: @ECHO %separator%
    9: @ECHO.
   10:  
   11: IISRESET
   12: @ECHO.
   13:  
   14: @ECHO --[ Installing MyCustomDll.dll ]---------------------------------
   15: %gacutil% -i "C:\Temp\bin\MyCustomDll.dll" -f /silent
   16: IF NOT ERRORLEVEL 0 GOTO PAUSE
   17: @ECHO.
   18:  
   19: GOTO:eof
   20:  
   21: :PAUSE
   22: @ECHO %separator%
   23: @ECHO Error while installing last DLL
   24: @ECHO %separator%
   25: PAUSE

 

Go.cmd

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5: Color 0A
    6: CLS
    7:  
    8: :MENU
    9: @ECHO.
   10: @ECHO.
   11: @ECHO.
   12: @ECHO.
   13: @ECHO %separator%
   14: @ECHO MyCustom Sharepoint website
   15: @ECHO %separator%
   16: @ECHO (1) Install Features
   17: @ECHO (2) Create Site Definition 
   18: @ECHO (3) Create Webs
   19: @ECHO (4) Copy Files
   20: @ECHO (G) GAC DLL
   21: @ECHO (D) Delete Webs
   22: @ECHO (x) Exit
   23: @ECHO.
   24: CHOICE /C 1234567GDX /M "please make a choice : "
   25:     IF ERRORLEVEL 10 GOTO:eof
   26:     IF ERRORLEVEL 9 GOTO DELETEWEBS
   27:     IF ERRORLEVEL 8 GOTO GAC
   28:     IF ERRORLEVEL 4 GOTO COPYFILES
   29:     IF ERRORLEVEL 3 GOTO WEBS
   30:     IF ERRORLEVEL 2 GOTO SITEDEFINITION
   31:     IF ERRORLEVEL 1 GOTO FEATURES
   32:  
   33:  
   34: :FEATURES
   35: @ECHO.
   36:     @CALL InstallFeatures.cmd
   37: GOTO:MENU    
   38:     
   39:  
   40: :SITEDEFINITION
   41: @ECHO.    
   42:     @CALL CreateSiteDefinition.cmd
   43: GOTO:MENU    
   44:     
   45:  
   46: :WEBS
   47: @ECHO.
   48:     @CALL CreateWebs.cmd
   49: GOTO:MENU    
   50:     
   51:  
   52: :DELETEWEBS
   53: @ECHO %separator%
   54: @ECHO.
   55:     @CALL DeleteWebs.cmd
   56: GOTO:MENU    
   57:  
   58:  
   59: :COPYFILES
   60: @ECHO %separator%
   61: @ECHO.
   62:     @CALL CopyFiles.cmd
   63: GOTO:MENU
   64:  
   65:  
   66: :GAC
   67: @ECHO %separator%
   68: @ECHO.
   69:     @CALL GAC.cmd
   70: GOTO:MENU

 

 

Cheers!

 

Maxime

Comments

  • Anonymous
    February 24, 2008
    PingBack from http://www.biosensorab.org/2008/02/24/site-definition-developer-helper-scripts/

  • Anonymous
    February 24, 2008
    Your content, as always, is great! I'll offer this tidbit to you in regards to batch files... You can use the built-in label, "eof": goto :eof Instead of: goto :END rem more commands :END

  • Anonymous
    February 24, 2008
    Thanks, I'll add it up on my "next" release.  One more DOS command that I didn't know.  We had some fun this week when looking at this, a bunch of senior developers scratching our heads learning DOS commands and having fun. Of course, I could have used Powershell but that'll be for another time! Thanks, Maxime

  • Anonymous
    March 22, 2008
    This is a follow-up to my Site Definition Helper scripts post . As described in that post, we were looking