I'm doing some research in code generation from xsd schema files. My requirements:
(see also my other questions: How can I generate multiple classes from xsd’s with common includes? and How can I generate comments from xs:documentation tags in a wsdl?
I have found the following options:
Did I miss any? Because (1), (2) and (5) do not generate 2.0 code, and I have problems with serializing code from (3). What do you use when generating code?
I believe XSD2Code is the best tool currently available (in 2011).
I recently went through the same process at work of analysing the available tools out there so i thought i would provide an updated answer that relates to VS2010.
Our main driver was that xsd.exe does not generate XML doc from the XSD annotations, which we wanted as we have hundreds of type definitions. I tried all the tools listed above as well as others and most were either deprecated, unmaintained or unable to match the current functionality of xsd.exe available in VS2010.
Xsd2Code however is a superb tool and seems to be actively maintained. It provides all the functionality that was listed above and a lot more - the CodePlex page also has great examples of how the various options affect output.
It also has tight VS integration, including context menu integration and a custom build tool (which means that if you reference the XSDs in your project and specify the custom tool, it will automatically update the code as you update the XSD). All in all saved us a lot of work.
A quick summary of the other tools i looked at:
Addendum: If you do decided to go ahead with XSD2Code, there are a number of issues i found working with the command-line tool. In particular, there are some bugs with the argument processing that require some arguments to be in a certain order as well as some undocumented dependencies (eg - automatic parameters & .NET version are order specific and dependent). The following are the steps i used to generate the code using XSD2Code and then cleanup the output - take the bits that apply to you as necessary:
Run the following batch file to generate the initial code, changing the paths to the correct locations:
@echo off set XsdPath=C:\schemas set OutPath=%XsdPath%\Code set ExePath=C:\Progra~1\Xsd2Code set Namespace=InsertNamespaceHere echo.Starting processing XSD files ... for /f %%a IN ('dir %XsdPath%\*.xsd /a-d /b /s') do call:ProcessXsd %%a echo.Finished processing XSD files ... echo.&pause& goto:eof :ProcessXsd %ExePath%\Xsd2Code %~1 %Namespace% %XsdPath%\Code\%~n1%.cs /pl Net35 /if- /dc /sc /eit echo.Processed %~n1 goto:eof
Perform the following steps to tidy up the generated code, as necessary:
Hope that helps someone.
I have not yet checked this out, but Linq2XSD might be a useful alternative.
I'm going to give this one a shot. LINQ with XSD generation would be better than any of these tools you mentioned - provided it works nicely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With