2017-05-04 53 views
3

我需要從網絡核心中的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)] 
+0

儘管如此,您應該更多地指定您的問題。有沒有什麼能讓生成的類**不能與.NET Core一起工作? xsd應該生成一個普通的poco類,其屬性爲max(xml和datacontract屬性應該在.NET Core中可用) – Tseng

回答

5

我現在已經解決了這個問題,將添加到我的項目中。

  • System.Xml.XmlSerializer

解決辦法:刪除序列化屬性的問題,除了DesignerCategoryAttribute

  • Newtonsoft.json

解決辦法:刪除DesignerCategoryAttribute

現在可以編譯xsd.exe生成的類並在網絡核心中使用它

1

有actualy沒有辦法,但如果你看到this它是未來的.NET核心版本的一部分(.NET核心1.2 2017年第二季度發佈)。

如果您需要更多信息,請參閱此discuss,特別是此point

+0

好的,2017年第2季度,他們提供了xsd支持。 2017年第二季度是否有任何日期? – joakimja