Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Msbuild dotnet core中存在重复的错误消息_Msbuild_Visual Studio Code_.net Core_Dotnet Cli - Fatal编程技术网

Msbuild dotnet core中存在重复的错误消息

Msbuild dotnet core中存在重复的错误消息,msbuild,visual-studio-code,.net-core,dotnet-cli,Msbuild,Visual Studio Code,.net Core,Dotnet Cli,复制步骤 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

复制步骤

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报告了两次


我的问题是:有没有办法避免重复报告错误?

您可以创建自己的msbuild记录器,而不是使用默认的控制台记录器。这里有很好的说明:

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


dotnet build/noconsolelogger/logger:YourCustomLogger.dll
第二个错误是控制台记录器摘要的一部分。这可以通过将
/clp:NoSummary
传递到msbuild来禁用。但是,当CLI是
dotnet build
的第一个msbuild参数时,当前CLI中存在错误。在它之前添加任何其他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
(在该版本上打开了一个)

。。。我注意到同样的行为。它看起来像是一种摘要,因为它是在生成失败消息之后显示的。我可以问一下,这对你来说是否是一个问题,以及为什么会是一个问题吗?@EmielKoning,当我收到stylecopWorks所描述的500条警告时,这让我很恼火。谢谢。可与最新的2.1.4版本配合使用,而无需使用dotnet MSBuild。此解决方案太过分了。我在寻找一个被接受的答案。