问题描述
有一些 XSD 和 WSDL.我想从它们生成 C# 代码.我使用了 svcutil.exe,但它不会从 XSD 注释生成 XML 注释:
There are some XSDs and WSDLs. I want to generate C# code from them. I used svcutil.exe, but it does not generate XML-comments from XSDs annotations:
<annotation>
<documentation>VERY USEFULL DOCUMENTATION</documentation>
</annotation>
我想要这个在生成的文件中:
I want this inside generated file:
public class SomeData
{
/// <summary>
/// VERY USEFULL DOCUMENTATION
/// </summary>
public string SomeField
{...}
}
另一个问题:如何强制 svcutil.exe 为每个类生成一个文件?(我知道我可以使用 Resharper 的重构来将类移动到单独的文件,但我不喜欢这个解决方案)
Another question: how to force svcutil.exe to generate one file per class? (I know that I can use refactor from Resharper to move classes to separate files, but I don't like this solution)
那么如何使用来自 XSD 和 WSDL 的 XML 注释生成多个文件(每个类一个文件)
So how to generate multiple files (one file per class) with XML-comments from XSDs and WSDLs
推荐答案
您可以使用 WCFExtras+ http://wcfextrasplus.codeplex.com/.
You might be able to use the WCFExtras+ http://wcfextrasplus.codeplex.com/.
- 使 WCFExtras.dll 对 svcutil.exe 可见(例如将它们放在同一目录中)
将此部分添加到客户端应用程序的 app.config,或放置在新的配置文件中并使用/svcutilConfig 开关调用 svcutil
- Make WCFExtras.dll visible to svcutil.exe (such as by putting them in the same directory)
add this section to the app.config of the client app, or place in a new config file and invoke svcutil with the /svcutilConfig switch
<configuration>
<system.serviceModel>
<client>
<metadata>
<wsdlImporters>
<extension type="WCFExtras.Wsdl.Documentation.XmlCommentsImporter, WCFExtras" />
</wsdlImporters>
</metadata>
</client>
</system.serviceModel>
</configuration>
示例命令行,其中 configfile.xml 是上面的配置文件:SvcUtil.exe [服务网址]/svcutilConfig:[configfile.xml 的路径]
example command line, where configfile.xml is the config file above:SvcUtil.exe [service url] /svcutilConfig:[path to configfile.xml]
这篇关于如何使用来自 WSDL 和 XSD 的注释生成 .NET 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!