3

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.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Jake Pearson
  • 27,069
  • 12
  • 75
  • 95

3 Answers3

1

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
  • 25,849
  • 11
  • 66
  • 104
  • 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 Dec 30 '09 at 21:28
1

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".

user19371
  • 284
  • 2
  • 4
0

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
  • 12,330
  • 10
  • 51
  • 64