Generate C# class from XSD file.

I have an existing C# file, generated a long time ago from XSD definition.
The XSD files were changed, and proxy class should be regenerated.
I’ve tried to use XML Schema Definition Tool (Xsd.exe) to generate C# class, but it  returned the error: “The datatype is missing”.
I’ve actually have two XSD files -outer and imported
Thanks to the post: XSD.exe is kicking my butt, man…redux , it pointed me to specify all necessary files on the commandline.
Note that name of generated file is combined from the files listed
  
I’ve created the batch file to be able to rerun it  
CallXSD.BAT
@call “C:Program FilesMicrosoft Visual Studio 8VCvcvarsall.bat” x86
xsd.exe outer.xsd imported.xsd /classes /l:cs /n:MyNamespace

rem rename  outer_imported.cs as outer.cs 
pause

By some reason the generated file created in some non-default encoding, which inserts 3 characters

 in the beginning.It is a minor annoyance, but when I delete them, VS shows me a warning, that wrong encoding could prevent keeping history.
 
The next issue was that the new XSD(.Net Framework 2.0 and 3.5) generates C# classes differently with what 1.0/1.1 XSD.exe did.
In a few places 1.1 version generated custom collection of objects, but new XSD.EXE generates array of objects, so I have to change the calls to generated classes.

Another problem with XSD generated classes is that it disables  step into debugging even on methods that you  extended in partial classes by specifying DebuggerStepThroughAttribute for classes. Workarounds are described in XSD.exe and DebuggerStepThrough post.  Issue reported to MS Feedback.

I should try An XSD to .NET language code class generator that adds real punch to Microsoft’s XSD Tool.
or Sample Code Generator 1.4.2.1

Another issue was that authors of XSD file added   xsd:choice  elements and it creates extra ItemsChoiceType array and enum.I described how I addressed it in my post XmlChoiceCollection class to access XSD generated properties for choice XML elements

 

That’s pity, that minor changes in XSD file causes different class properties to be generated and essential code  changes to access the new properties.