Skip to content

How to generate common types once and avoid XmlSerializer generator type collisions for MeterInfoType? #571

@snikeguo

Description

@snikeguo

schemas.zip

Short background We have two shared XSDs at the repo root (V2G_CI_AppProtocol.xsd and xmldsig-core-schema.xsd) that should be generated once into HomePlug.V2G.Common. Three standards folders (din_spec, iso15118_2, iso15118_20) each reference those two shared XSDs and should generate their own C# into profile-specific namespaces (e.g. HomePlug.V2G.DIN70121, HomePlug.V2G.ISO15118_2, HomePlug.V2G.ISO15118_20). When generating code for each standard, the shared XSD types must be resolvable for imports/includes but must not be regenerated (no duplicate types).

Problem 1 — generation / configuration question When generating the three standard outputs, what is the recommended project JSON / generator options to:

resolve imports/includes to the root XSDs so generation succeeds, and
avoid emitting duplicate types from V2G_CI_AppProtocol.xsd and xmldsig-core-schema.xsd into each standard assembly?
Concretely: does the generator support an “excludeSchemas” (or equivalent) option, or should we rely on searchPaths and explicitly omit the root XSDs from each standard’s schema list? A minimal example JSON for:

HomePlug.V2G.Common (generating the two root XSDs), and
one standard project (e.g. din_spec) that resolves imports but does not re-emit the common types would be very helpful.
Problem 2 — XmlSerializer generator error (runtime / build) After generating the C# sources, running Microsoft.XmlSerializer.Generator (sgen) fails with a type collision for MeterInfoType because multiple generated assemblies include types with the same XML element name. Example build output:

[.NET Xml Serialization Generation Utility, Version 10.0.0] The top XML element 'MeterInfoType' from namespace '' references distinct types HomePlug.V2G.ISO15118_2.MeterInfoType and HomePlug.V2G.ISO15118_20.MeterInfoType. Use XML attributes to specify another XML name or namespace for the element or types. C:\Users\Administrator.nuget\packages\microsoft.xmlserializer.generator\10.0.0\build\Microsoft.XmlSerializer.Generator.targets(51,5): warning MSB3073: 命令“dotnet Microsoft.XmlSerializer.Generator "obj\X64\Debug\net10.0\HomePlug.dll" --force --quiet obj\X64\Debug\net10.0\sgen.rsp”已退出,代码为 1。 C:\Users\Administrator.nuget\packages\microsoft.xmlserializer.generator\10.0.0\build\Microsoft.XmlSerializer.Generator.targets(52,5): warning : SGEN: Failed to generate the serializer for HomePlug.dll. Please follow the instructions at https://go.microsoft.com/fwlink/?linkid=858594 and try again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions