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

标签 asp.net-core .net-core xsd.exe

我需要从网络核心中的 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?) 

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)]

最佳答案

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

  • System.Xml.XmlSerializer

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

  • 解决方案:删除 DesignerCategoryAttribute

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

    关于asp.net-core - 从net core中的xsd文件生成一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43778093/

    相关文章:

    c# - xsd2code 使用 xsd.exe 还是使用自己的代码生成算法?

    .net - xsd.exe输出文件名

    c# - ASP.Net Core MVC 中的本地化不起作用 - 无法找到资源文件

    sql-server - 我无法使用 Entity Framework Core 更新数据库

    .Net 核心和插件

    .net-core - .NET Core的新.csproj格式的Roslyn工作区

    asp.net-core - IIS 只能支持 Blazor 服务器客户端的三个实例?

    asp.net-core - 无法加载类型 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute'

    c# - 如何在一个地方为所有 Controller 验证 Request.Headers ["Authorization"]?

    .net - 我们可以在 xsd.exe 工具生成的类中控制类型名称吗