SHARE:

How to resolve the issue “Failed to install Nuget package” when adding a new gRPC service reference

The problem

If like me you tried to (via the GUI) to add a new gRPC service in Visual Studio 2019 and you got that error:

You are definitely not alone!

The cause

You are probably running lower version of Visual Studio 2019 < 16.4

The issue come from Visual Studio 2019 16.3.x and lower.

Here is the original explanation from Bill Hiebert (Microsoft):

If it is an asp.net core web project it should be checking for a reference to Grpc.AspNetCore of at least 2.23.2 and installing that if missing.  You have 2.25 so that should be a no-op.  It will also attempt to uninstall any of the following (since they are included in Grpc.AspNetCore) if it finds them at the version specified or lower, it should ignore newer versions like your reference to Grpc.Tools 2.25.0. This is what is happening on machines which are running 16.4. 16.3 did not have the check for Grpc.AspNetcore so could attempt to add the lower versioned dependency packages which would cause a downgrade failure from Nuget and the error you are seeing.

The solution

At this point you have two solutions:

Big thank you to Bill Hiebert who helped me to fix that issue!

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.