从网络核心中的xsd文件生成一个类
问题描述:
我需要从网络核心中的xsd生成一个类。 在dotnet标准中,我使用了命令行xsd filename.xsd /c.
但是如何在net core中创建这个类。 任何人都知道如何做到这一点?从网络核心中的xsd文件生成一个类
当我添加一个用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?)
属性在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)]
答
我现在已经解决了这个问题,将添加到我的项目中。
- System.Xml.XmlSerializer
解决办法:删除序列化属性的问题,除了DesignerCategoryAttribute
- Newtonsoft.json
解决办法:删除DesignerCategoryAttribute
现在可以编译xsd.exe生成的类并在网络核心中使用它
尽管如此,您应该更多地指定您的问题。有没有什么能让生成的类**不能与.NET Core一起工作? xsd应该生成一个普通的poco类,其属性为max(xml和datacontract属性应该在.NET Core中可用) – Tseng