Jake Pearson
Jake Pearson

Reputation: 27757

Have vs.net automatically execute xsd.exe everytime time xsd is modified

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.

Upvotes: 3

Views: 1460

Answers (3)

ng5000
ng5000

Reputation: 12590

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

Upvotes: 0

user19371
user19371

Reputation: 284

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

Upvotes: 1

TcKs
TcKs

Reputation: 26632

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.

Upvotes: 1

Related Questions