Skip to content

Commit

Permalink
feat: Pack protos in NuGet package for Google.Api.CommonProtos
Browse files Browse the repository at this point in the history
Additionally, add msbuild support so that the common protos will be
used implicitly by Grpc.Tools if IncludeGoogleApiCommonProtos is set to true.
  • Loading branch information
jskeet committed Oct 11, 2023
1 parent cfd9fd6 commit 4eb8a70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Google.Api.CommonProtos/Google.Api.CommonProtos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="[3.23.0, 4.0.0)" />
<None Remove="proto-header.txt" />
<None Include="protos\**\*.proto" Pack="true" PackagePath="content/protos" />
<None Include="build\*.targets" Pack="true" PackagePath="build" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Google.Api.CommonProtos/build/Google.Api.CommonProtos.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This targets file allows the common protos, which are bundled in the NuGet package, to be included in Grpc.Tools compilation. -->
<!-- This saves the developer having to find and copy these files to the right location. -->
<PropertyGroup>
<!-- The path of the proto files. Content from the nupkg. -->
<GoogleApiCommonProtos_ProtosPath>$( [System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../content/protos) )</GoogleApiCommonProtos_ProtosPath>
</PropertyGroup>

<!-- Run immediately before the Protobuf_BeforeCompile extension point. -->
<!-- Only include protos if project has set <IncludeGoogleApiCommonProtos> property to true. -->
<Target Name="GoogleApiCommonProtos_BeforeCompile"
BeforeTargets="Protobuf_BeforeCompile"
Condition=" '$(IncludeGoogleApiCommonProtos)' == 'true' ">
<PropertyGroup>
<!-- Add nupkg proto files by including path in Protobuf_StandardImportsPath. -->
<Protobuf_StandardImportsPath>$(Protobuf_StandardImportsPath);$(GoogleApiCommonProtos_ProtosPath)</Protobuf_StandardImportsPath>
</PropertyGroup>
<Message Text="Included proto files at $(GoogleApiCommonProtos_ProtosPath) in import path." Importance="high" />
<Message Text="Updated proto imports path: $(Protobuf_StandardImportsPath)" Importance="high" />
</Target>
</Project>

0 comments on commit 4eb8a70

Please sign in to comment.