Repository navigation
Route task output to the build log instead of the console - #17412
Conversation
MSBuild tasks that write to System.Console bypass the build loggers. The output is not attributed to a project or target, it does not appear in binlogs, and once tasks run concurrently on shared nodes it interleaves arbitrarily with output from other tasks. Three tasks did this: InstallDotNetCore forwarded the dotnet-install script's stdout and stderr to the console and announced already-installed runtimes there. PublishBuildToMaestro emitted four Azure Pipelines logging commands to the console. The agent locates the ##vso[ prefix with IndexOf rather than StartsWith, so the console logger's leading indentation does not affect them, and the same file already emits an artifact.upload command through Log.LogMessage a few lines earlier. GenAPITask returned Console.Out as the writer for generated API text whenever no output path was set.
There was a problem hiding this comment.
Pull request overview
Routes MSBuild task output that previously went to System.Console into MSBuild’s task logging APIs so it is attributed correctly, captured by loggers/binlogs, and doesn’t interleave unpredictably under concurrent builds.
Changes:
InstallDotNetCore: forwarddotnet-installstdout/stderr toLog.LogMessageand adjust importance for the “already installed” notice.PublishBuildToMaestro: emit Azure Pipelines##vso[...]commands viaLog.LogMessageinstead ofConsole.WriteLine.GenAPITask: default output now goes to the build log via aTextWriterthat forwards generated output line-by-line toLog.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.DotNet.GenAPI/GenAPITask.cs | Changes default GenAPI output sink from console to build log via a log-backed TextWriter. |
| src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishBuildToMaestro.cs | Routes ##vso[...] logging commands through MSBuild logging instead of direct console writes. |
| src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs | Routes script output and status messaging through MSBuild logging instead of stdout/stderr. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
Resolves conflicts with the four extracted PRs that have since merged: dotnet#17412 (console output to build log), dotnet#17426 (unused build tasks), dotnet#17427 (BuildTask base class) and dotnet#17428 (static task state). Conflict resolution: - Base classes take main's spelling. Main derives tasks from the short `Task` with Microsoft.Build.Utilities imported, except in the four files that also import System.Threading.Tasks and therefore keep the fully qualified name. The multithreading attribute and IMultiThreadableTask from this branch are layered on top. - The three tasks deleted as dead on main stay deleted, dropping their annotations with them. - GenAPITask.LogTextWriter and several using blocks were duplicated by the automatic merge; kept main's copy in each case. Main's LogTextWriter logs from a dedicated LogPendingLine rather than overriding Flush, so an explicit Flush() no longer emits a partial line. - Kept main's wording for the GetPackageDescription cache comment and its fix for the "erreleasea" typo. Co-authored-by: Copilot <[email protected]> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
|
Note This comment was generated by GitHub Copilot CLI. The dependency update in dotnet/msbuild#15157 drops the publishing-command fix from #17412: the package version increases, but the new Arcade commit is from The public pinned sources show the regression:
The fix is to backport the publishing-command changes from #17412 to |
|
/backport to release/11.0 |
|
Started backporting to |
MSBuild tasks that write to
System.Consolebypass the build loggers: the output isn't attributed to a project, doesn't appear in binlogs, and interleaves arbitrarily once tasks run concurrently on shared nodes. Three tasks still did this. No behavioral change intended.InstallDotNetCore— dotnet-install's stdout/stderr and the "already installed" notice now go toLog. Failures are unaffected; the task already checksExitCodeand callsLogError.PublishBuildToMaestro— four##vsocommands moved toLog.LogMessage(High). They still reach the agent:Command.TryParsefinds the prefix withIndexOf, notStartsWith(there's a unit test for">>> ##vso[...]"), so the logger's indentation doesn't matter. The same file already emitsartifact.uploadthis way 30 lines earlier, as doesPushToBuildStorage.GenAPITask—GetOutputreturnedConsole.Outwhen noOutputPathwas set; it now buffers a line at a time intoLog. Lines are passed with no format arguments, since generated C# is full of braces.Console usage elsewhere is left alone —
PipelinesLoggeris anILogger, HelixJobMonitoris a standalone tool, and the rest are CLI entry points or tests.