1

I'm getting a build error in my Vazor project:

Google.Protobuf.Tools proto compilation is only supported by default in a C# project

However, I'm not doing proto compilation in this project. The codegen project is a C# project, which I'm referencing in my Vazor project. Apparently the compiler isn't smart enough to figure that out.

Here's the relevant snippet from the Google.Protobuf.Tools.Targets file:

<!-- Check configuration sanity before build. -->
<Target Name="_Protobuf_SanityCheck" BeforeTargets="PrepareForBuild">
  <Error
    Condition=" '$(Protobuf_ProjectSupported)' != 'true' "
    Text="Google.Protobuf.Tools proto compilation is only supported by default in a C# project (extension .csproj)" />
</Target>

This started when I added the Grpc.AspNetCore package, so I could do this in Startup.vb:

Services.AddGrpc

I tried commenting out the <Error /> element, and that works, but it's a hack—and a pretty lousy one at that. Q&As like this one come close, but they don't really address the problem.

Here's a repro project. Build VazorMVC1 and you'll see the error.

Is there a dignified way to suppress this error so my project can build, perhaps in declarative MSBuild syntax, without my having to alter the targets file?

InteXX
  • 6,135
  • 6
  • 43
  • 80
  • I presume this is happening because an import of the targets file got added into your project file. Have you considered removing it from your project file? That would remove the error without editing the targets file. (In my experience, best way to edit a project file is right-click and choose "Unload Project", then in VS 2019 you can double-click to edit, in earlier you can right-click to edit.) – Craig Mar 29 '22 at 13:08
  • The targets file is in the `Grpc.Tools` package's folder hierarchy, not the project. `Grpc.AspNetCore` depends on `Grpc.Tools`, and `Grpc.Tools` is the one doing the project language check; it doesn't care that I'm not doing any codegen in the VB.NET project, only that it's installed there. I'm hoping there's an elegant way in declarative MSBuild syntax to disable that checking from within the project, but that's probably a long shot. – InteXX Mar 29 '22 at 13:59
  • 1
    I added a repro link to my question. – InteXX Mar 29 '22 at 15:54
  • 1
    Ok, I confirmed that you don't have a direct import in the project file. I don't have any other ideas, then. I already have issues with PackageReference, and this seems like another shortcoming. It might be worth raising an issue with either Grpc.Tools or the Microsoft build tools. – Craig Mar 30 '22 at 13:38
  • Thanks for checking back in. FYI I just discovered a problem that puts gRPC on the outs for my project: it won't run on any but the absolute newest [versions of IIS](https://learn.microsoft.com/en-us/aspnet/core/grpc/supported-platforms?view=aspnetcore-6.0#supported-aspnet-core-servers). Oh, for the wonderful days of WCF... – InteXX Mar 30 '22 at 19:38

0 Answers0