8

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)]
joakimja
  • 2,707
  • 2
  • 17
  • 25
  • You should bit more specify your question though. Is there anything that makes the generated class **not** work with .NET Core? xsd should generate a normal poco class with attributes at max (xml and datacontract attributes should be available in .NET Core already) – Tseng May 04 '17 at 13:04

3 Answers3

7

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

joakimja
  • 2,707
  • 2
  • 17
  • 25
2

netstandard2.0 can compile xsd.exe generated files with no problems

fiorebat
  • 3,431
  • 2
  • 18
  • 18
  • 1
    where do you find xsd.exe? – Zeus82 Jul 27 '20 at 12:17
  • 1
    as https://learn.microsoft.com/it-it/dotnet/standard/serialization/xml-schema-definition-tool-xsd-exe I can confirm: "The XML Schema Definition tool (Xsd.exe) usually can be found in the following path: C:\Program Files (x86)\Microsoft SDKs\Windows\{version}\bin\NETFX {version} Tools\" – fiorebat Jul 27 '20 at 13:52
  • 2
    If your Italian is not adequate, see https://learn.microsoft.com/dotnet/standard/serialization/xml-schema-definition-tool-xsd-exe – R. Schreurs Apr 13 '21 at 16:47
1

There is no way actualy but if you see this it's a part of the future .net core release (.Net Core 1.2 release on Q2 2017).

If you want more Info, see this discuss and specially this point.

Francois Borgies
  • 2,378
  • 31
  • 38