Search code examples
protobuf-net

How do I enable protobuf-net.BuildTools OneOf support via project file?


The documentation seems to indicate this should be possible but I'm not having any luck getting this working as described.

net5.0 project, protobuf-net (3.0.101) and protobuf-net.BuildTools(3.0.101) are the only NuGet references

simple .proto file defined as:

syntax = "proto3";

message ExampleMessage {
    oneof SomeGroup {
        int32 foo = 1;
        string bar = 3;
        double baz = 4;
    }
}

.csproj file snippet:

<ItemGroup>
  <AdditionalFiles Include="example.proto" OneOf="enum"/>
</ItemGroup>

Code generates, but does not include any enum definition.

I know this is similar to another recent question, but that one doesn't address attributes and I wasn't permitted to comment there.


Solution

  • Short version: there was an error in the tool bundling; I have fixed this, and with an imminent build (currently working through the CI build), this should be resolved; the config in the question now works, with the additional output in the C#:

    public SomeGroupOneofCase SomeGroupCase => (SomeGroupOneofCase)__pbn__SomeGroup.Discriminator;
    
    public enum SomeGroupOneofCase
    {
        None = 0,
        Foo = 1,
        Bar = 3,
        Baz = 4,
    }