svcutil exlude/reuse refrenced assemblies

南楼画角 提交于 2019-11-29 02:36:09
svcutil /?

gives

/reference:<file path> - Add the specified assembly to the set of assemblies 
                         used for resolving type references. If you are 
                         exporting or validating a service that uses 3rd-party
                         extensions (Behaviors, Bindings and BindingElements)
                         registered in config use this option to locate 
                         extension assemblies that are not in the GAC.  
                         (Short Form: /r)

So running svcutil with /r:myassembly.dll should make it.

Thanks for your help. Got this working eventually with the following commands:

SET BACKENDROOT=C:\SomePath\Development\Backend\bin
SET DATAMODELSBASE=C:\SomePath\Development\DataModels\bin
SET OUTFOLDER=C:\SomeOutputFolder
SET REFRENCED_ASSEMBLIES=/r:%DATAMODELSBASE%\Jall.DataModels.Consignment.dll
SET REFRENCED_ASSEMBLIES=%REFRENCED_ASSEMBLIES% /r:%DATAMODELSBASE%\Jall.DataModels.SomethingElse.dll

SET SVCFLAGS=/enableDataBinding /s /a /tcv:Version35

::Generate metadata
svcutil %BACKENDROOT%\Jall.Backend.Consignment.DLL /t:metadata -d:%OUTPUTFOLDER%

::Generate proxy with shared types
svcutil %OUTPUTFOLDER%\*.wsdl %OUTPUTFOLDER%\*.xsd %SVCFLAGS% /ser:DataContractSerializer %REFERENCED_ASSEMBLIES /o:test.cs

Note that the /ser:DataContractSerializer had to be used for this to work. And another annoyance is that if types such as datatables/datasets etc is used (not that they really should though) their assemblies have to be included or svcutil will mess up generating the metadata.

IE:

SET SHAREDASSEMBLIES=%SHAREDASSEMBLIES% /r:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll

If you run svcutil without arguments, you'll see it has several functions. I think you could do what you want with two invocations:

  • One to generate metadata from your binary, with a command line like svcutil /serviceName:<myServiceName> <pathToAssemblyWithConfigFile>. This outputs .wsdl and .xsd files.
  • Another to generate code from the metadata, with switches specifying where to find existing types for the data contracts: svcutil /reference:<assemblyPath> *.wsdl *.xsd.

I've tried doing this in one step before, but when svcutil is in "code generation" mode, it expects metadata as input, not assemblies. So generate metadata first!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!