svcutil exlude/reuse refrenced assemblies

后端 未结 3 1769
Happy的楠姐
Happy的楠姐 2020-12-16 06:55

Is it possible to use svcutil to reuse/exclude referenced types, as with visual studio.

I have multiple projects, my types/datamodels are stored in separate assembli

相关标签:
3条回答
  • 2020-12-16 07:37

    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!

    0 讨论(0)
  • 2020-12-16 07:52
    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.

    0 讨论(0)
  • 2020-12-16 07:57

    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
    
    0 讨论(0)
提交回复
热议问题