Home  /  Blog  /  How to : generate multiple schemas by script

How to : generate multiple schemas by script

March 2021

In this short How-to guide we will show you with an example how to generate multiple schemas by script. It is useful to be able to generate several schema at once. For example, if you have a large number of schema and they are updated to a new version. It can take a long time to go through the schema generation one schema at a time, building a script can be a considerable time saver.

In another context, it can also be useful to generate the code from a build server. For example when a check-in is performed on one or more schemas. Or simply when a compilation is triggered on the build server. As you can see, there are many reasons to automate these processes. The example script below selects all the schemas of a directory and generates one by one the corresponding classes. The "Parameters" variable contains code generation options that you can customize to suit your needs.

The documentation that details all the command line options can be found here : How to run from command-line tool

Step-by-step guide

  • Create a file on your disk with the .bat extension.
  • Edit it to insert the code below which can be used as a basis for building your own script.
  • Run it in the root directory where your schemas are located.
@echo off
set WorkingFolder=c:\temp
set Parameters=/p NetCore /classinfiles
set Extension=.xsd
set X2C=C:\Program Files(x86)\Xsd2Code\xsd2code.exe
for %% f in (% WorkingFolder %\*% Extension %) do (
       echo "fullname: %%f"
  echo "%X2C%" %% f % Parameters %
  "%X2C%" %% f % Parameters %