Generate a class from xsd file in net core

joakimja picture joakimja · May 4, 2017 · Viewed 9.5k times · Source

I need to generate a class from an xsd in net core. In dotnet standard I used commandline xsd filename.xsd /c. But how to I create this class in net core. Anyone knows how to do this?

When I add a class generated with xsd.exe I get several errors.

Example

    Error   CS0234  The type or namespace name 'SerializableAttributeAttribute' does not exist in the namespace 'System' (are you missing an assembly reference?)


Error   CS0234  The type or namespace name 'DesignerCategoryAttribute' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) 

Error   CS0234  The type or namespace name 'XmlTypeAttributeAttribute' does not exist in the namespace 'System.Xml.Serialization' (are you missing an assembly reference?)

Error   CS0246  The type or namespace name 'AnonymousType' could not be found (are you missing a using directive or an assembly reference?) 

Attributes from a class in autogen file

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]

Answer

joakimja picture joakimja · Jun 5, 2017

I have now solved this issue with adding nugets to my project.

  • System.Xml.XmlSerializer

Solution: Removes the serializations attribute issues except the DesignerCategoryAttribute

  • Newtonsoft.json

Solution: Removes the DesignerCategoryAttribute

Now it is possible to compile the xsd.exe generated class and use it in net core