Skip to content

Commit 1619af4

Browse files
committed
Add proto files and msbuild target to gRPC JSON transcoding to automatically include external dependencies
1 parent 1c385f4 commit 1619af4

File tree

4 files changed

+440
-1
lines changed

4 files changed

+440
-1
lines changed

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Microsoft.AspNetCore.Grpc.JsonTranscoding.csproj

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>HTTP API for gRPC ASP.NET Core</Description>
44
<PackageTags>gRPC RPC HTTP/2 REST</PackageTags>
@@ -28,5 +28,14 @@
2828
<Reference Include="Google.Api.CommonProtos" />
2929
<Reference Include="Google.Protobuf" />
3030
<Reference Include="Grpc.AspNetCore.Server" />
31+
32+
<None Update="protos\google\api\*.proto">
33+
<Pack>true</Pack>
34+
<PackagePath>content</PackagePath>
35+
</None>
36+
<None Include="build\*.targets">
37+
<Pack>true</Pack>
38+
<PackagePath>build</PackagePath>
39+
</None>
3140
</ItemGroup>
3241
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- This targets file allows annotations.proto and http.proto, which are bundled in package, to be included in Grpc.Tools compilation. -->
4+
<!-- This saves the developer having to find and copy these files to the right location when doing gRPC JSON transcoding. -->
5+
<PropertyGroup>
6+
<!-- The path of the proto files. Content from the nupkg. -->
7+
<GrpcJsonTranscoding_ProtosPath>$( [System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../content/protos) )</GrpcJsonTranscoding_ProtosPath>
8+
</PropertyGroup>
9+
10+
<!-- Run immediately before the Protobuf_BeforeCompile extension point. -->
11+
<!-- Only include protos if project has set <IncludeHttpRuleProtos> property to true. -->
12+
<Target Name="GrpcJsonTranscoding_BeforeCompile"
13+
BeforeTargets="Protobuf_BeforeCompile"
14+
Condition=" '$(IncludeHttpRuleProtos)' == 'true' ">
15+
<PropertyGroup>
16+
<!-- Add nupkg proto files by including path in Protobuf_StandardImportsPath. -->
17+
<!-- See more info about Grpc.Tools build integration at https://github.com/grpc/grpc/blob/master/src/csharp/BUILD-INTEGRATION.md. -->
18+
<Protobuf_StandardImportsPath>$(Protobuf_StandardImportsPath);$(GrpcJsonTranscoding_ProtosPath)</Protobuf_StandardImportsPath>
19+
</PropertyGroup>
20+
<Message Text="Included proto files at $(GrpcJsonTranscoding_ProtosPath) in import path." Importance="high" />
21+
<Message Text="Updated proto imports path: $(Protobuf_StandardImportsPath)" Importance="high" />
22+
</Target>
23+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2015, Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
package google.api;
18+
19+
import "google/api/http.proto";
20+
import "google/protobuf/descriptor.proto";
21+
22+
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
23+
option java_multiple_files = true;
24+
option java_outer_classname = "AnnotationsProto";
25+
option java_package = "com.google.api";
26+
option objc_class_prefix = "GAPI";
27+
28+
extend google.protobuf.MethodOptions {
29+
// See `HttpRule`.
30+
HttpRule http = 72295728;
31+
}

0 commit comments

Comments
 (0)