4

I have an XSD schema I need to include within my program, to validate some user input XML. The schema will need to be regularly updated. (By the programmer.)

My current method to include this is hold a reference to it within Resources.resx - however, this doesn't seem ideal as it requires me to duplicate all my enum's between the XSD and the C#.

I've also looked at converting the XSD file to a runtime class using xsd.exe - however, as I understand, this requires running a separate process outside of Visual Studio, which makes it more complex to update, and requires the process being detailed for future authors.

I can't imagine this is an unusual situation - is there a method by which this is commonly done, where I can remove the duplication in my current method, but still not have the need to manually process the schema on each update?

  • 2
    Could you run XSD.EXE as a pre-build or post-build step? – Moby Disk Feb 10 '15 at 21:04
4

Create a pre-build step to run XSD.EXE before each build.

I found 2 other answers on SO that explain how to automate this: https://stackoverflow.com/questions/14897750/automate-xsd-exe-during-build https://stackoverflow.com/questions/2990684/automatically-generate-xsd-to-c-sharp-in-visual-studio-ide

The second one refers to a tool called XSD2code which is on codeplex. I don't see a nuget package for it though.

2

The answer largely depends on how often you expect your types to change in a way that would force changes to the schema.

If changes occur rarely or not at all, the easiest thing to do from a maintainer's standpoint may very well be to duplicate the values in a static XSD document.

If changes occur frequently, you may be better off coming up with a way to generate the XSD as a build artifact. This will eliminate duplication and ensure that it will be up-to-date, but there may be a significant up-front cost to put it together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.