如何抑制编译目标的错误

发布于 2025-01-17 21:16:42 字数 1163 浏览 2 评论 0原文

我的 Vazor 项目中出现构建错误:

默认情况下,仅在 C# 项目中支持 Google.Protobuf.Tools 原型编译

但是,我不会在该项目中进行原型编译。 codegen 项目是一个 C# 项目,我在我的 Vazor 项目中引用了它。显然编译器不够聪明,无法弄清楚这一点。

以下是 Google.Protobuf.Tools.Targets 文件中的相关片段:

<!-- 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>

这是在我添加 Grpc.AspNetCore 包时启动的,因此我可以在 Startup 中执行此操作.vb

Services.AddGrpc

我尝试注释掉 元素,这确实有效,但它是一种 hack,而且是一个非常糟糕的 hack。问题与这个很接近,但他们并没有真正解决问题。

这是一个重现项目。构建 VazorMVC1,您将看到错误。

是否有一种有尊严的方法来抑制此错误,以便我的项目可以构建(也许使用声明性 MSBuild 语法),而无需更改目标文件?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文