Reputation: 4622
I'm using dotnet standard 2.0 (Visual Studio 2017) for gRPC. This is how my whole project looks like:
Messages.proto
syntax = "proto3";
package Messages;
message IdRequest{
int32 id = 1;
}
message NameResponse{
string name=1;
}
Name.proto
syntax = "proto3";
package Services;
import public "proto/messages.proto";
service NameService{
rpc GetNameById(Messages.IdRequest) returns (Messages.NameResponse);
}
Common.proj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="proto\messages.proto" />
<None Remove="proto\name.proto" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.10.1" />
<PackageReference Include="Grpc" Version="2.24.0" />
<PackageReference Include="Grpc.Core" Version="2.24.0" />
<PackageReference Include="Grpc.Tools" Version="2.24.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="proto\messages.proto" />
<Protobuf Include="proto\name.proto" />
</ItemGroup>
</Project>
The project builds successfully however the final Common.dll has no Messages namespace and I cannot really reference IdRequest or NameResponse.
So where am I making the mistake that hides Messages namespace?
Upvotes: 5
Views: 2068
Reputation: 169
I know this is so old, but in case it is helpful for someone else. The documentation for gRPC has greatly improved since the asking of this question.
Looking at the tags associated, but also from the discussions and screenshots from here, I'm going to make the assumption that the project was working with csharp, as this makes a difference. I believe the namespaces are not generated correctly because the option "csharp_namespace" is missing.
The service will also have its namespace changed because of this amendment.
Message.proto:
syntax = "proto3";
package Messages;
option csharp_namespace = "Messages";
message IdRequest{
int32 id = 1;
}
message NameResponse{
string name=1;
}
Name.proto:
syntax = "proto3";
package Services;
option csharp_namespace = "Messages";
import "proto/Messages.proto";
service NameService{
rpc GetNameById(Messages.IdRequest) returns (Messages.NameResponse);
}
Upvotes: 1
Reputation: 1189
In your project file into the Protobuf-tag you need to add the GrpcServices attribute or else no code is created:
<ItemGroup>
<Protobuf Include="proto\messages.proto" GrpcServices="Server" />
<Protobuf Include="proto\name.proto" GrpcServices="Server" />
</ItemGroup>
Upvotes: 4