简体   繁体   English

多个XSD架构文件到C#类

[英]Multiple XSD schema files to C# classes

What is the best way to generate C# classes from multiple XSD schema files? 从多个XSD架构文件生成C#类的最佳方法是什么?

Some XSD schema files may have dependency to the other, I am trying to avoid duplicated C# classes being generated. 一些XSD架构文件可能依赖于另一个,我试图避免生成重复的C#类。

Use the XSD.EXE program, but pass all of the schemas to the program on the same command line. 使用XSD.EXE程序,但在同一命令行上将所有模式传递给程序。

For example: 例如:

> xsd /c qbxmltypes130.xsd QBUqbxmlops130.xsd QBUqbxmlso130.xsd QBUqbxml130.xsd

Will emit a class named: 将发出一个名为的类:

qbxmltypes130_QBUqbxmlops130_QBUqbxmlso130_QBUqbxml130.cs

In this case these are Quickbooks Desktop SDK xsd files, and the final file has types it depends on in the first 3 files. 在这种情况下,这些是Quickbooks Desktop SDK xsd文件,最终文件具有前3个文件所依赖的类型。 It won't emit on its own, but with its dependencies it works as desired. 它不会自行发射,但依赖它可以按需运行。

Note that there is a /parameters:<file> switch that allows you to specify a file of command line parameters. 请注意,有一个/parameters:<file>开关,允许您指定命令行参数的文件。 I remember using it in one project for a similar reason. 我记得出于类似的原因在一个项目中使用它。

XSD.EXE doc has the parameter format. XSD.EXE doc具有参数格式。

I for one found the examples in the MSDN doc a bit lacking. 我一个人发现MSDN文档中的示例有点缺乏。 Here's an example parameters file for the issue codemeit described: 这是一个描述的问题codemeit的示例参数文件:

<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
<generateClasses language='CS' namespace='Namespace.subnamespace'>
    <schema>FirstSchema.xsd</schema>
    <schema>AnotherSchema.xsd</schema>
    <schema>LastSchema.xsd</schema>
</generateClasses>
</xsd>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM