Since we adopted AuthorIT as our HAT a few months back, everyone has been impressed with how it has changed our department’s workflow. The only real holdouts have been the installs developers, who think that anything that isn’t stored in Microsoft Visual SourceSafe is completely devoid of value.

So, to keep from having to deal with VSS any more (heck–ditching VSS was one of the greatest points in the AuthorIT sales pitch for us), I wrote a batch file to handle publishing and checking in the output to VSS.

The batch file takes parameters on the command line for all of the publishing and VSS information, so it can be scheduled through Windows Scheduler to automate the entire publish and check-in process.

The batch file, including its help information, is included after the jump.

This batch file is also available for download as a txt file.

@ECHO OFF

REM ================================================================================
REM ================================================================================
REM ===                                                                          ===
REM === AUTOPUB.BAT                                                              ===
REM ===                                                                          ===
REM === This batch file is used to publish help projects and store them in       ===
REM === the appropriate SourceSafe database. To create automated publishes,      ===
REM === schedule this batch file to run in the Windows Scheduler.                ===
REM ===                                                                          ===
REM === NOTE: This script relies on freeware mail sender BLAT for notifications. ===
REM === More information about BLAT available at http://www.blat.net.            ===
REM ===                                                                          ===
REM ================================================================================
REM ===                                                                          ===
REM === VERSION HISTORY                                                          ===
REM === 11/01/06   First version released   Will Sansbury (www.willsansbury.com) ===
REM ===                                                                          ===
REM ================================================================================
REM ===                                                                          ===
REM === EXAMPLE USAGE                                                            ===
REM === AUTOPUB vsspath vssuser vsspass vssproj aitpath aitbook aitfrmt          ===
REM ===         [aituser] [aitpass]                                              ===
REM ===                                                                          ===
REM === NOTE: The example command above should be entered on one line. If        ===
REM === values contains spaces, you must place quotation marks around the        ===
REM === parameter, as demontrated on the path to the AuthorIT publishing         ===
REM === path.                                                                    ===
REM ===                                                                          ===
REM ================================================================================
REM ===                                                                          ===
REM === COMMAND LINE VARIABLES                                                   ===
REM === This batch file uses the following variables:                            ===
REM ===     vsspath = The VSS Server location, such as ZIMMVSS$               ===
REM ===     vssuser = The user name that you want to use to access VSS           ===
REM ===     vsspass = The password of the user that you want to use to           ===
REM ===               access VSS                                                 ===
REM ===     vssproj = The VSS project name relative to $/, such as $/IMAIL/Help  ===
REM ===     aitpath = The location of the publish folder on the local drive,     ===
REM ===               such as                                                    ===
REM ===               C:Program FilesAuthorIT V4PublishingXHTMLProjectName ===
REM ===     aitbook = The AuthorIT object ID of the book being published         ===
REM ===     aitfrmt = The code for the format publishing to                      ===
REM ===               For the format number, use:                                ===
REM ===                       1 for Word                                         ===
REM ===                       8 for XHTML                                        ===
REM ===                      16 for CHM                                          ===
REM ===     aituser = (OPTIONAL) The AuthorIT username to use when publishing.   ===
REM ===               If not specified, uses the default.                        ===
REM ===     aitpass = (OPTIONAL) The password for the AuthorIT username to       ===
REM ===               use when publishing.  If not specified, uses the default.   ===
REM ===                                                                          ===
REM ================================================================================
REM ===                                                                          ===
REM === WHAT THIS BATCH FILE DOES                                                ===
REM === For each help project, this batch file:                                  ===
REM ===     1. Using command line values, sets the variables to access the       ===
REM ===        correct VSS server                                                ===
REM ===     2. Sets the working folder for the project to the local              ===
REM ===        publish folder under                                              ===
REM ===        C:Program FilesAuthorIT V4Publishing                          ===
REM ===     3. Checks out the project from source safe to prepare for            ===
REM ===        publishing changes                                                ===
REM ===     4. Publishes the specified AuthorIT book to the specified            ===
REM ===        format                                                            ===
REM ===     5. Checks the project into SourceSafe                                ===
REM ===                                                                          ===
REM ================================================================================
REM ================================================================================

REM // Default variables - Set these for your environment.
set aituser=user
set aitpassword=password
set vsspath="C:Program FilesMicrosoft Visual StudioVSSwin32ss.exe"
set notifemail=you@yourdomain.com
set aitsql=sqlserver
set aitdb=database

REM // Check of /help, /h, /? or help as first variables, then show HELPINFO
IF (%1) == (/help) GOTO HELPINFO
IF (%1) == (/h) GOTO HELPINFO
IF (%1) == (/?) GOTO HELPINFO
IF (%1) == (help) GOTO HELPINFO

REM // Check for presence of all required parameters
IF (%1) == () GOTO MSSGPRMS
IF (%2) == () GOTO MSSGPRMS
IF (%3) == () GOTO MSSGPRMS
IF (%4) == () GOTO MSSGPRMS
IF (%5) == () GOTO MSSGPRMS
IF (%6) == () GOTO MSSGPRMS
IF (%7) == () GOTO MSSGPRMS

REM // Assign all command line parameters to variables
set SSDIR=%1
set SSUSER=%2
set SSPWD=%3
set project=%4
set workingfolder=%5
set aitbook=%6
set aitformat=%7

REM // If AuthorIT username and password are supplied, use instead of defaults.
IF NOT (%8) == () set aituser=%8
IF NOT (%9) == () set aitpassword=%9

REM // Set the VSS working folder to the project publish folder.
%vsspath% Workfold %project% %workingfolder%

REM // Check out the project recursively.
%vsspath% Checkout -R %project%

REM // Publish the project from AuthorIT.
"C:Program FilesAuthorIT V4AITPublish.exe" /sql"%aitsql%|%aitdb%" /user"%aituser%" /pwd"%aitpassword%" /pub"%aitbook%|%aitformat%;" /exit

REM // Check the project back in to VSS.
%vsspath% Checkin -R %project%

REM // Send status and logs via e-mail
GOTO NOTIFY

:MSSGPRMS
@ECHO OFF
ECHO.
ECHO =========================================================
ECHO ERROR! One or more required variables were not specified.
ECHO =========================================================
ECHO.
GOTO MAINHELP

:HELPINFO
@ECHO OFF
ECHO Publishes AuthorIT book and stores output in Microsoft
ECHO Visual Source Safe.
ECHO.

:MAINHELP
@ECHO OFF
ECHO AUTOPUB vsspath vssuser vsspass vssproj aitpath aitbook
ECHO         aitfrmt [aituser] [aitpass]
ECHO.
ECHO    vsspath    The VSS Server location, such as ZIMMVSS$
ECHO    vssuser    The user name that you want to use to access VSS
ECHO    vsspass    The password of the user that you want to use to
ECHO               access VSS
ECHO    vssproj    The VSS project name relative to $/, such as $/IMAIL/Help
ECHO    aitpath    The location of the publish folder on the local drive, such
ECHO               as C:Program FilesAuthorIT V4PublishingXHTMLProjectName
ECHO    aitbook    The AuthorIT object ID of the book being published
ECHO    aitfrmt    The code for the format publishing to
ECHO               For the format number, use:
ECHO                      1 for Word
ECHO                      8 for XHTML
ECHO                     16 for CHM
ECHO    [aituser]  The AuthorIT username to use when publishing.
ECHO               If not specified, uses a default value.
ECHO    [aitpass]  The AuthorIT password to use when publishing.
ECHO               If not specified, uses a default value.
ECHO.
GOTO END

:NOTIFY
REM // Send notification and attach logs
blat - -body "Log files attached." -to %notifemail% -subject "[AUTO_HELP] Status" -attach "C:Program FilesAuthorIT V4Logs*"

REM // Clear logs so next time only relevant logs are sent.
REM // Also keeps logs directory from growing out of control.
DEL /Q "C:Program FilesAuthorIT V4Logs*"

:END