sRPC.Tools - Garados007/srpc GitHub Wiki

With Version 1.4.1 a new NuGet package sRPC.Tools was introduced that wraps the sRPCgen compiler and simplify the support with this. This package can directly integrate with your project and automaticly compile your proto files.

Installation

To get this package you need to add the NuGet package sRPC.Tools. The easiest way is this:

dotnet add package sRPC.Tools

Alternativly you can add this with the NuGet package manager or you add this to your csproj file:

<ItemGroup>
  <PackageReference Include="sRPC.Tools" Version="2.2.0"> <!-- <= insert here the newest version avaible -->
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
  </PackageReference>
</ItemGroup>

Configuration

This package can run in two different modes: Single File or Full Project.

Single File

This is the default mode.

For this each proto file in your Project has to be configured to be compiled with sRPC.Tool. Dependencies are not automaticly resolved.

To add a files you need to select the proto file in Visual Studio and set in their Properties the Build step to Protobuf. Now you can configure some additional settings of it.

If you don't use Visual Studio you can add these files directly in your csproj file. To do this you need to add the following snippet to it:

<ItemGroup>
  <None Remove="your\file.proto" />
  <Protobuf Include="your\file.proto" />
</ItemGroup>

The following settings are supported to apply to the Protobuf object:

Setting Default Description
NamespaceBase $(TargetName) The default namespace in your proto files. This will be used to locate the generated files
SrpcExt .service.cs The extension the generated files from sRPCgen should get. This is the generated code of your services.
ProtoExt .g.cs The extension the generated files from protoc should get. This is the generated code of your messages.
ProtoCompile True If sRPCgen should generate its required files on its own. For this refere to the sRPCgen documentation.

Full Project

For this all proto files in your project are automaticly compiled. To achive this you need to add this to your csproj file:

<PropertyGroup>
    <Srpc_AutoSearchProj>true</Srpc_AutoSearchProj>
</PropertyGroup>

With this any specific configuration to proto files (see Single File mode) will be ignored.

Common settings

In both modes you can add settings that will apply to all files and set the defaults for the Single File mode.

The supported settings are defined if you add the following in you csproj:

<PropertyGroup>
    <Setting_Name>Setting_Value</Setting_Name>
</PropertyGroup>

Where you replace Setting_Name and Setting_Value with the corresponding name and value of the setting.

Some settings can be set if you define the environment variable.

Setting Environment Variable Default Value Description
Protobuf_ToolsOs PROTOBUF_TOOLS_OS your system One of windows, linux or macosx. Defines your operating system
Protobuf_ToolsCpu PROTOBUF_TOOLS_CPU your cpu One of x86 or x64. Defines your cpu architecture
Protobuf_ProtocFullPath PROTOBUF_PROTOC Defines the path of the protoc compiler. Normaly it will use the included protoc compiler
Protobuf_SrpcFullPath PROTOBUF_SRPC Defines the path of the sRPCgen compiler. Normaly it will use the included sRPCgen compiler
Srpc_NamespaceBase SRPC_NAMESPACE_BASE $(TargetName) The basic namespace for your protobuf files. This defines where the generated files should be located
Srpc_SrpcExt SRPC_SRPC_EXT .service.cs The extension for your generated service files
Srpc_ProtoExt SRPC_PROTO_EXT .g.cs The extension for your generated message files
Srpc_AutoSearchProj SRPC_AUTO_SEARCH_PROJ false defines the mode which files should be generated
Srpc_EmptySupport SRPC_EMPTY_SUPPORT false enables special support for google.protobuf.Empty types
Srpc_IgnoreUnwrap SRPC_IGNORE_UNWRAP google.protobuf.Empty Ignores the unwrapped call for some request messages. The types are delimited with ;. The Environment variable is always in the list included
⚠️ **GitHub.com Fallback** ⚠️