Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate xsd.exe during build

I need a way to automatically regenerate *.cs files during build, based on *.xsd files, preferably without involving any custom add-ins. This needs to run on the CI build as well.

I'm not sure if I'm missing something obvious, or is this really tricky as it seems to me?

like image 320
Marcin Seredynski Avatar asked Feb 15 '13 15:02

Marcin Seredynski


1 Answers

I use this script:

@echo off
cd %1
call :treeProcess %2 "XSDs"
cd ..
goto :eof

:treeProcess
rem From http://stackoverflow.com/a/8398621/298754
echo Processing %2
for %%f in (*.xsd) do call :buildXSD %%f %1 %2 %%~nf
for /D %%d in (*) do (
    cd %%d
    call :treeProcess %1 %2.%%d
    cd ..
)
exit /b

:buildXSD
%2 %1 /c /n:%3.%4%

with a prebuild event of

call "$(ProjectDir)"XSDBuilder.bat "$(ProjectDir)"\XSDs "$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\@InstallationFolder)bin\xsd.exe"

This will recursively parse every .xsd file in a folder in the project root called XSDs, and will assign a namespace based on the folder structure.

like image 113
Bobson Avatar answered Nov 13 '22 11:11

Bobson