Skip to content

Instantly share code, notes, and snippets.

@alfeg
Last active September 5, 2018 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfeg/235be2c85b0894075a9e37d04985d84b to your computer and use it in GitHub Desktop.
Save alfeg/235be2c85b0894075a9e37d04985d84b to your computer and use it in GitHub Desktop.
MSBuild target file that handle Grpc.Tools generation, And example on how to include
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
<PackageReference Include="Grpc" Version="1.14.2" />
<PackageReference Include="Grpc.Tools" Version="1.14.2" />
</ItemGroup>
<Import Project="proto.targets" />
</Project>
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BuildProto" BeforeTargets="Compile;BeforeBuild">
<XmlPeek XmlInputPath="$(MSBuildProjectFullPath)"
Query="//PackageReference[@Include='Grpc.Tools']/@Version" >
<Output TaskParameter="Result" ItemName="GrpcToolsVersion" />
</XmlPeek>
<PropertyGroup>
<GrpcTools>$(NuGetPackageRoot)\grpc.tools\@(GrpcToolsVersion)\tools\windows_x64</GrpcTools>
<GrpcPlugin>protoc-gen-grpc=$(GrpcTools)\grpc_csharp_plugin.exe</GrpcPlugin>
</PropertyGroup>
<ItemGroup>
<ProtoFiles Include="*.proto" />
<ProtoOutput Include="Proto\*.cs" />
</ItemGroup>
<MakeDir Directories="Proto" />
<Delete Files="@(ProtoOutput)" />
<ItemGroup>
<Args Include="--csharp_out $(MSBuildProjectDirectory)\Proto" />
<Args Include="--grpc_out $(MSBuildProjectDirectory)\Proto --plugin=$(GrpcPlugin)" />
</ItemGroup>
<Exec Command="$(GrpcTools)\protoc.exe @(Args, ' ') %(ProtoFiles.Identity)" ConsoleToMSBuild="true"></Exec>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment