Synchronize XSD from an InfoPath document with a SharePoint project for server-side XSD validation

In order to implement server-side XSD validation against an InfoPath form submission, I had to pull the XSD from the InfoPath document archive (XSN file) and use that to update an embedded resource in a SharePoint solution project (including automated checkout/checkin in TFS). I was able to do it using a batch file.

Pretty specialized need, but maybe somebody could make use of it someday ;).

Note: If you want to use this code, you'll have to combine some of the lines that were too long to display.

 @echo off 

rem ***********************************************************
rem This batch file is used to extract the XSD files from each 
rem of the InfoPath forms, and copy them into the source tree
rem Download and install the Microsoft CAB SDK from 
rem http://support.microsoft.com/kb/310618 to c:\cabsdk
rem *********************************************************** 

rem IMPORTANT: Set these values to your system. Do not include 
rem trailing slashes, and include values in quotes if necessary 

set CABSDK_PATH=c:\cabsdk\bin
set ROOT=C:\projects\projectname
set TFS_USERNAME="domain\user.name"
set TFS_PASSWORD=password 

rem These should be relatively fixed
set FORMS_ROOT=%ROOT%\Project.Namespace\12\TEMPLATE\Layouts\infopathForms
set XSD_ROOT=%ROOT%\Project.Namespace\12\Resources
set TF_PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE 

echo.
echo ********* InfoPath Form 1 *********
echo.
set FORM_PATH=%FORMS_ROOT%\Form 1\Form1.xsn
set XSD_PATH=%XSD_ROOT%\Form1.xsd
set RETURN=FINISH
goto UPDATE_SCHEMA 

:FINISH
goto FINISH_BATCH

:UPDATE_SCHEMA
echo Checking file out...
"%TF_PATH%\tf.exe" edit "%XSD_PATH%" 
    /login:%TFS_USERNAME%,%TFS_PASSWORD% /noprompt >/nil 

echo Extracting file...
del myschema.xsd
"%CABSDK_PATH%\extract.exe" "%FORM_PATH%" myschema.xsd >/nil 

echo Replacing file...
copy myschema.xsd "%XSD_PATH%" >/nil 

echo Checking file in...
"%TF_PATH%\tf.exe" checkin "%XSD_PATH%" 
    /login:%TFS_USERNAME%,%TFS_PASSWORD% /noprompt 
    /comment:"Automated checkin from XsdExtractor script" >/nil 

goto %RETURN% 

:FINISH_BATCH