Can colors used in default MSBUILD logger be modified?

前端 未结 2 424
迷失自我
迷失自我 2021-01-21 07:49

The default MSBuild logger does nice color-coding of output lines in the console window - if you happen to use the default black background for console windows. I find using bl

相关标签:
2条回答
  • 2021-01-21 08:27

    Using PowerShell, I suppose PS enthusiasts can provide a better script:

    #
    # Run MSBuild With Custom Color.ps1
    #
    msbuild C:\some_path\your.sln | foreach-object -process  { 
        switch ($_){
            { $_.tolower().contains("warning")} {Write-Host $_ -foregroundColor DarkBlue}
            { $_.tolower().contains("error")} {Write-Host $_ -foregroundColor DarkRed}  
            default {Write-Host $_ -foregroundColor Black}
        }
    }
    
    0 讨论(0)
  • 2021-01-21 08:34

    The colors are basically hardcoded. What you can do out of the box, with MSBuild 4.0, is completely disable colors using the /clp:disableconsolecolor option when invoking MSBuild.exe (for more information on the /clp option run MSBuild.exe /?). With older MSBuild versions you can use MSBuild.exe arguments 2>&1| findstr /r ".*". See this answer for more details.

    If you want to have different colors, you need to implement your own (console) logger, which is not too hard, and use that (/logger: option, combined with /noconsolelogger to turn off the default console logger).

    0 讨论(0)
提交回复
热议问题