Automatically generate c# serialization classes from XSDs
So I have put my first code sample up on MSDN’s Code Gallery. The code sample demonstrates a way to automatically generate serialization classes from XSD schemas using a Text Template (T4 Template). There’s no need to run XSD.exe each time, instead you can run the Custom Tool of the Text Template and have all serialization classes generated of your XSDs.
Click here to navigate to the code sample.
Copy of the code sample description
Introduction
Sometimes you may have the need to do serialization of messages within BizTalk Server. The normal way to do this, is using XSD.exe to generate serialization classes. One change in your XSD and you have to grab XSD.exe again. But what if we can automate this process? So we don’t need to run XSD.exe each time XSDs are updated.
Building the Sample
This sample is built in Visual Studio 2013 and only holds a C# class library.
Description
Code generation in Visual Studio is often done with Text Templates (T4 Templates). The Text Template used in this sample will generate the serialization classes for all the XSDs found within the same project.
1) Create a C# Class Library project
Create a project like you always would.
2) Add the XSDs you want to use for serialization
After creating the project, add some XSDs to the project that can be used to generate the serialization classes. In the sample two XSDs have been used.
3) Add the Text Template below
Now add a Text Template to the Visual Studio project and copy the code from the code sample into the added artifact.
4) Run the Custom Tool to generate the serialization classes
After the Text Template has been added and the code has been copied in it (and the file was saved), right-click the XmlSerialization.tt and choose Run Custom Tool.
After running the tool, you’ll notice the serialization classes that were generated by the Text Template. You can now use these classes all around your code or even in your BizTalk projects.