1

I configured the .csproj file as follows:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net9.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
        <PackageReference Include="protobuf-net" Version="3.2.56"/>
        <PackageReference Include="protobuf-net.BuildTools" Version="3.2.52">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="protobuf-net.Grpc" Version="1.2.2"/>
        <PackageReference Include="protobuf-net.Grpc.ClientFactory" Version="1.2.2"/>
    </ItemGroup>
    <ItemGroup>
        <AdditionalFiles Include="Protos\*.proto" Services="Client"/>
    </ItemGroup>
</Project>

The folder with the proto files is located at: ConsoleApp2\Protos

The proto file looks like this:

syntax = "proto3";

package MyApp;

service MyService {
  rpc SayHello (HelloRequest) returns (HelloReply);
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

The problem is that only messages are being generated, but not the service.

// <auto-generated>
//   This file was generated by a tool; you should avoid making direct changes.
//   Consider using 'partial classes' to extend these types
//   Input: Test.proto
// </auto-generated>

#region Designer generated code
#pragma warning disable CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
namespace MyApp
{

    [global::ProtoBuf.ProtoContract()]
    public partial class HelloRequest : global::ProtoBuf.IExtensible
    {
        private global::ProtoBuf.IExtension __pbn__extensionData;
        global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
            => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);

        [global::ProtoBuf.ProtoMember(1, Name = @"name")]
        [global::System.ComponentModel.DefaultValue("")]
        public string Name { get; set; } = "";

    }

    [global::ProtoBuf.ProtoContract()]
    public partial class HelloReply : global::ProtoBuf.IExtensible
    {
        private global::ProtoBuf.IExtension __pbn__extensionData;
        global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
            => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);

        [global::ProtoBuf.ProtoMember(1, Name = @"message")]
        [global::System.ComponentModel.DefaultValue("")]
        public string Message { get; set; } = "";

    }

}

#pragma warning restore CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
#endregion

What could be the cause?

I’ve tried different configuration options, but none of them worked.

1 Answer 1

1

As far as I see in the source repo Services (some code) has two options grpc and wcf:

+services={grpc;wcf} Semi-colon list of service metadata to support.

Changing AdditionalFiles to use grpc:

<AdditionalFiles Include="Protos\*.proto" Services="grpc"/>

Generates the IMyService interface for me:

[global::ProtoBuf.Grpc.Configuration.Service(@"MyApp.MyService")]
public partial interface IMyService
{
    global::System.Threading.Tasks.ValueTask<HelloReply> SayHelloAsync(HelloRequest value, global::ProtoBuf.Grpc.CallContext context = default);
}

P.S.

For some reason VS Code decompiler was not regenerating files for me so I've added explicit source generator output:

<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  <CompilerGeneratedFilesOutputPath>generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.