Do I really need whole Grpc.Core NuGet package to use Google PubSub in simple C# application

Viewed 352

I am creating a simple C# desktop application that is pulling messages from Google Cloud PubSub. I noticed that PubSub is using Grpc.Core package that when installed is more than 500 mb! It contains many files that I don't need(for mac, android, etc.) and it doesn't seem reasonable to use such package if my application size is only few mb. There is a discussion here: Why is Grpc.Core NuGet package so big?

In comments section it is said that it is possible to target more specific packages to suit specific needs. So my question is - is there more specific package/s that can be used to simply pull messages from Cloud PubSub to desktop application?

1 Answers

I feel your pain. (In fact, I feel it many times over. When I do a complete build of the google-cloud-dotnet repo that I work on, it pulls in those libraries many times over, and ends up being vast.)

It would be nice if you could add a sort of "negative dependency" to say "I don't want Grpc.Core even though Google.Cloud.PubSub.V1 depends on it indirectly, please use Grpc.Net.Client instead", but I don't believe there's any simple way of doing that in MSBuild projects.

We do make a "best-effort" attempt to support Grpc.Net.Client via the Google.Api.Gax.Grpc.GrpcNetClient package - you can depend on that package and then set the GrpcAdapter property in a ClientBuilderBase<TClient> to GrpcNetClientAdapter.Default. However:

  • The Pub/Sub libraries are slightly trickier to reconfigure than others, due to the manual layer of code wrapping the generated code. (I can look into how to perform that configuration if you're interested.)
  • We haven't done significant testing with Grpc.Net.Client, and the Pub/Sub library in particular performs a lot of streaming; while it should all just work, it's possible that there could be problems.
  • Doing that doesn't actually remove the Grpc.Core dependency anyway - so you'd need to manually remove the files you don't need.

There really isn't a more specific package that you can target - all I can suggest is that you delete the files you don't need. You could do that in a build target that runs post compile, for example. It's possible that there's some cunning way to tell MSBuild that when it would copy (say) the iOS libraries into a specific location, just exclude them instead - but I don't know enough MSBuild to say how you'd do that (when they're being copied due to a dependency rather than due to the project itself).

Related