从net core中的xsd文件生成一个类

joa*_*mja 4 xsd.exe .net-core asp.net-core

我需要从net core中的xsd生成一个类.在dotnet标准中我使用了命令行xsd filename.xsd /c. 但是如何在net core中创建这个类.谁知道怎么做?

当我添加用xsd.exe生成的类时,我得到了几个错误.

    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?) 
Run Code Online (Sandbox Code Playgroud)

来自autogen文件中的类的属性

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

joa*_*mja 7

我现在已经通过向项目中添加nugets解决了这个问题.

  • System.Xml.XmlSerializer

解决方案:删除除DesignerCategoryAttribute之外的序列化属性问题

  • Newtonsoft.json

解决方案:删除DesignerCategoryAttribute

现在可以编译xsd.exe生成的类并在net core中使用它