Add gRPC server to existing C# .NET Core solution

Problem

I need to add a gRPC server to an existing Windows service solution in Visual Studio, but the only way I can find is to create a separate project and transform it into a library. I also can’t add a proto file using the “add an element” menu, even with the gRPC core nugget installed.

Solution

To add a proto file, create a .txt file, add proto information to it, then edit it. To have the ability to add proto files, change the project balise to Sdk="Microsoft.NET.Sdk.Web" (this will add all the functions available for a new gRPC project).

To prevent having to copy the proto file when making a client, add a service reference and point it to the proto file of the server. This will ensure that any edits made to the server’s proto file will be synchronized.

Solution:

To add a gRPC server to an existing Windows service solution in Visual Studio, follow these steps:

  1. Create a .txt file, and add proto information to it.
  2. Change the project balise to Sdk="Microsoft.NET.Sdk.Web".
  3. Save the file with the .proto extension.
  4. Add the file to your project.
  5. Install the gRPC core nugget.
  6. Build the project.

To prevent having to copy the proto file when making a client, add a service reference and point it to the proto file of the server. This will ensure that any edits made to the server’s proto file will be synchronized.