Last active
September 5, 2018 11:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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