【问题标题】:Duplicate error messages in .NET Core - error CS0116.NET Core 中的重复错误消息 - 错误 CS0116
【发布时间】:2017-11-18 19:32:31
【问题描述】:

复制步骤

dotnet new console
(introduce a bug in Program.cs)
dotnet restore
dotnet build

典型的输出是:

Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]

Build FAILED.

Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.77

可以看到报错CS0116两次。

有没有办法避免重复报告错误?

【问题讨论】:

  • 奇怪...我注意到同样的行为。它看起来像是一种摘要,因为它显示在 Build FAILED 消息之后。我可以问一下这对您来说是否以及为什么是一个问题?
  • @EmielKoning,当我收到来自 stylecop 的 500 条警告时,我感到很烦

标签: msbuild visual-studio-code .net-core dotnet-cli


【解决方案1】:

您可以制作自己的 MSBuild 记录器,而不是使用默认的控制台记录器。 Build loggers 里面确实有很好的说明。

基本上,您可以制作自己的记录器来捕获所有数据,然后在最后发出一个简单的摘要。

dotnet build /noconsolelogger /logger:YourCustomLogger.dll

【讨论】:

  • 这个解决方案太过分了。我正在寻找一个像接受的答案一样的答案。
【解决方案2】:

第二个错误是控制台记录器摘要的一部分。这可以通过将 /clp:NoSummary 传递给 msbuild 来禁用。但是,当 CLI 是 dotnet build 的第一个 MSBuild 参数时,当前存在一个错误。在它之前添加任何其他 MSBuild 命令以使其工作。既然您想减少冗长,我们就使用/nologo 解决方法:

dotnet build -c Release /nologo /clp:NoSummary

但是,如果您直接使用 MSBuild,效果会很好:

dotnet msbuild /clp:NoSummary /p:Configuration=Release

在即将发布的 2.0.0 版本中,CLI 始终会覆盖 dotnet build 的摘要参数,因此您必须改用 dotnet msbuild(我为此打开了 issue on GitHub)。

【讨论】:

  • 完全按照描述工作。谢谢。
  • 与最新的 2.1.4 版本一起工作,无需使用 dotnet msbuild
猜你喜欢
  • 2019-12-25
  • 1970-01-01
  • 2020-09-07
  • 2020-12-01
  • 1970-01-01
  • 2018-06-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
相关资源
最近更新 更多