The gRPC team with their Grpc.Tools package have incorporated generation of .cs files from .proto files making this package mostly obsolete. I've switched to their tools myself, and so I'm no longer maintaining this. The gRPC tools solution currently lacks a few features this project has, but has features this project lacks. Missing features should be proposed on the gRPC project. No changes are planned for this project. See below for more information.
MSBuild target for automatic compiling of .proto files into .cs files.
Compatible with MSBuild 15.0 (Visual Studio 2017, .NET SDK projects, dotnet build)
Compatibility with earlier versions (and thus xbuild also) is conceivable but not implemented. Pull requests to add this are welcomed.
Install-Package MsBuild.ProtocolBuffers
Then just add .proto files to the project and .proto.cs files will be generated and included alongside them.
By default, all .proto
files in the project will be included in the code generation. You can customize this, however with the ProtoC
element in your msbuild.
<Target Name="ResetProtoC" BeforeTargets="ProtoCalcOutput">
<ItemGroup>
<ProtoC Remove="**\*.proto"/>
<ProtoC Include="proto\**\*.proto"/>
</ItemGroup>
</Target>
By default the output .proto.cs
files are placed alongside the .proto
files in the same directory.
You can override this by specifying what the base of your include is, and the base of your output:
<Target Name="ResetProtoC" BeforeTargets="ProtoCalcOutput">
<ItemGroup>
<ProtoC Remove="**\*.proto"/>
<ProtoC Include="proto-input\**\*.proto" InputBase="proto-input" OutputBase="proto-output"/>
</ItemGroup>
</Target>
You can also modify the default include path of .
with the <ProtoIncludes>
element:
<PropertyGroup>
<ProtoIncludes>.;..\..\my\other\protos</ProtoIncludes>
</PropertyGroup>