Automate xsd.exe during build

2020-03-03 08:38发布

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?

1条回答
地球回转人心会变
2楼-- · 2020-03-03 08:50

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.

查看更多
登录 后发表回答