Sdk: Quiet option to only print to console in case of error

Created on 23 Mar 2017  路  7Comments  路  Source: dotnet/sdk

Steps to reproduce

Run dotnet restore --v:q or dotnet build --v:q.

Expected behavior

Do not print to console unless there are errors.

Actual behavior

Prints to console:

Restoring packages for /xxx/app.csproj...
Generating MSBuild file /xxx/
Generating MSBuild file /xxx/
Writing lock file to disk. Path: /xxx/
Restore completed in 998.62 ms for /xxx/

NuGet Config files used:
    /Users/lutzroeder/.nuget/NuGet/NuGet.Config

Feeds used:
    https://api.nuget.org/v3/index.json

Environment data

.NET Command Line Tools (1.0.1)

Product Information:
Version: 1.0.1
Commit SHA-1 hash: 005db40cd1

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/1.0.1

enhancement

Most helpful comment

Seconded. That verbosity on quiet still prints pointless banner text is very odd:

root@64e3de0498da:~# dotnet build --verbosity q
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.31

All 7 comments

To add supporting information for this ticket.
when I run this batch file

@ECHO OFF
SET SemVer="1.0.0.0-local"

dotnet restore -v=q
dotnet build -v=q -c=Release /p:Version=%SemVer%
dotnet test .\HdrHistogram.UnitTests\HdrHistogram.UnitTests.csproj -v=q --no-build -c=Release
dotnet pack .\HdrHistogram\HdrHistogram.csproj --no-build --include-symbols -c=Release /p:Version=%SemVer%

I expect to either see no output (if there have been no errors) due to the -v=q argument. Alternatively, if output is to be expected by design (perhaps with -v=m) perhaps only the following output

Restore completed in 2.61 sec

Build succeeded.
    0 Warning(s)
    0 Error(s)

Total tests: 711. Passed: 711. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 46.5189 Seconds

  Successfully created package 'C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\bin\Release\HdrHistogram.1.0.0-local.nupkg'.
  Successfully created package 'C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\bin\Release\HdrHistogram.1.0.0-local.symbols.nupkg'.

However I get the following output

  Restoring packages for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.UnitTests\HdrHistogram.UnitTests.csproj...                                                                                                                     Restoring packages for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.Benchmarking\HdrHistogram.Benchmarking.csproj...                                                                                                               Restoring packages for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\HdrHistogram.csproj...
  Restoring packages for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.Examples\HdrHistogram.Examples.csproj...
  Lock file has not changed. Skipping lock file write. Path: C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\obj\project.assets.json
  Restore completed in 1.03 sec for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\HdrHistogram.csproj.        Lock file has not changed. Skipping lock file write. Path: C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.Examples\obj\project.assets.json
  Restore completed in 1.52 sec for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.Examples\HdrHistogram.Examples.csproj.                                                                                                              Lock file has not changed. Skipping lock file write. Path: C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.UnitTests\obj\project.assets.json                                                                                          Restore completed in 1.96 sec for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.UnitTests\HdrHistogram.UnitTests.csproj.        Lock file has not changed. Skipping lock file write. Path: C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.Benchmarking\obj\project.assets.json
  Restore completed in 2.61 sec for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.Benchmarking\HdrHistogram.Benchmarking.csproj.

  NuGet Config files used:
      C:\Users\leery\AppData\Roaming\NuGet\NuGet.Config
      C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

  Feeds used:
      https://api.nuget.org/v3/index.json
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:08.21
Test run for C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram.UnitTests\bin\Release\netcoreapp1.1\HdrHistogram.UnitTests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
[xUnit.net 00:00:01.2312426]   Discovering: HdrHistogram.UnitTests
[xUnit.net 00:00:03.9903768]   Discovered:  HdrHistogram.UnitTests
[xUnit.net 00:00:04.4618564]   Starting:    HdrHistogram.UnitTests
[xUnit.net 00:00:44.7241784]   Finished:    HdrHistogram.UnitTests

Total tests: 711. Passed: 711. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 46.5189 Seconds


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

  Successfully created package 'C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\bin\Release\HdrHistogram.1.0.0-local.nupkg'.
  Successfully created package 'C:\Users\leery\Source\Repos\HdrHistogram.NET\HdrHistogram\bin\Release\HdrHistogram.1.0.0-local.symbols.nupkg'.

Environment data

dotnet --version: 1.0.4

Runtime Environment:
OS Name: Windows 10
OS Version: 10.0.15063
Install path Path: C:\Program Files\dotnet\dotnet.exe

Seconded. That verbosity on quiet still prints pointless banner text is very odd:

root@64e3de0498da:~# dotnet build --verbosity q
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.31

I'd very much agree with @vincentwoo here; quiet isn't particularly quiet, especially with the needless banner.

Still an issue in current version:

  Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
  Copyright (C) Microsoft Corporation. All rights reserved.

So far, I have been using

dotnet build | grep error

or for colored output

echo tput setaf 1; dotnet build | grep error --color=never

This is pretty useful too

echo $(dotnet build | grep error) && dotnet watch run

Sadly, as this is a bash solution, it does not work from a Windows based environment. There will likely be a powershell equivalent, however

@btecu

Still an issue in current version:

Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.

Since .NET Core 3.0 SDK you can use the --nologo argument in order to hide the startup banner and the copyright message, see https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build#arguments

@0xced fyi, that particular message is emitted by MSBuild and suppressible by -nologo since .NET Core SDK 1.0.

You can also disable the summary with -consoleLoggerParameters:NoSummary.

I'm going to close this issue. It's not the default behavior (MSBuild on Windows was designed to be super chatty, not really following the UNIXy output-only-on-error philosophy), but it's accomplishable:

$ dotnet build -nologo -consoleLoggerParameters:NoSummary -verbosity:quiet

$ echo $?
0

$ echo "syntax error">> Class1.cs

$ dotnet build -nologo -consoleLoggerParameters:NoSummary -verbosity:quiet
Class1.cs(9,13): error CS1002: ; expected [/Users/raines/src/quiet/quiet.csproj]

$ echo $?
1

You can use a Directory.Build.rsp to make that the default for your repo if you like.

Was this page helpful?
0 / 5 - 0 ratings