C # - Maintenance of Classes generated from xsd file

7

I'm developing an application that uses classes generated from xsd files made available by the federal recipe with xsd.exe . I use them to serialize xml files from the objects of these classes after performing validation of what has been populated with xsd itself.

So far so good, the problem is that these xsd files change version when federal revenue is well understood, which will cause me a lot of headache to update xsd and the class generated from it for all clients.

It would force me to regenerate the C # class from the new version xsd and recompile the application. Which is very bad. Not to mention that if I eat ball and some client is left without the build updated, no xml generated by the application will be valid.

Okay enough of crying, as I am very amateur, I would like to ask: Is there a way to keep xsd files and their respective classes up to date without much manual labor?

    
asked by anonymous 04.10.2017 / 22:22

1 answer

1
The generated C # class is the representation of the Schema used, in the case described from the XML Schema Definition (XSD) file, so it stands to reason that if the original schema changes, the class must change accordingly. Ideally, you should not edit this class generated by XSD.exe. When there are changes, you must generate new classes using the XSD.exe tool, adjust the program code, compile and distribute the new version.

In fact:

1) The problem is that if the XSD changes radically, it is because things have been changed by who made the scheme, the government, unfortunately the code also has to be changed. When the change is incremental, less the code to be changed.

I think at the moment it is not possible to have a fully automated solution to update the application code / logic + database data as the government's XSD schemes change.

So for now what you can do is when there are changes in the XSD / layouts, run XSD.exe again by creating the new updated classes, and fine-tune the code and logic that these classes use.

2) To keep the application up-to-date on the client you can use ClickOnce with WPF , the < a href="https://www.bing.com/search?q=UWP%20AppInstaller"> .appinstaller or MSIX (preview) with UWP.

These technologies can be configured to check for a new version of the Application and then download and update it on the client.

    
23.06.2018 / 16:16