tags:

views:

501

answers:

3
+2  Q: 

vs.net xsd

In the past, I have used XSD.exe to create c# classes from an xsd. Today, I added an XSD to VS.NET 2008 SP1 and it automatically generated a dataset from my xsd, slick but I don't want a dataset. Is there a way to have vs.net automatically execute xsd.exe each time I modify my xsd.

+1  A: 

Select the *.xsd file, open Properties Window (F4 key) and delete "Custom Tool" and "Custom Tool Namespace". This will remove the "DataSet" issue.

The "c# class from an xsd" issue can be solved by another custom tool. Look at XsdCondeGenTool - there is sample, how to do it.

TcKs
XSDCodeGenerator's XSDGenerator.CustomTool is a good example of how to register a .net tool, but the XSDGenerator library is to me a simple example of how XSD.exe works and not a great xsd->c# tool in itself.
Greg Domjan
+1  A: 

I believe your best bet would be to run xsd.exe as a pre-build event, and setting the build action for your XSD to "None".

But then you haven't generated files automaticly included in project for compile.
TcKs
So the generated classes wil not be compiled :).
TcKs
A: 

Whether xsd.exe generates datasets or classes depends on the command line arguments. Extract from xsd /?:

/classes Generate classes for this schema. Short form is '/c'.

/dataset Generate sub-classed DataSet for this schema. Short form is '/d'.

A pre-build event could help with updating your auto generated classes when the schema changes. You might want to consider Nant instead. Nant is a port for .Net of the Java build script Ant. With Nant you can create reasonably complex build scripts that will be able to invoke xsd.exe. I also imagine they could help call out to some scripts that could update your project file to reference the xsd generated classes (not something I've done but very doable I would think).

ng5000