Skip to content

Route task output to the build log instead of the console - #17412

Merged
ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:console-to-build-log
Aug 26, 2026
Merged

ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:console-to-build-log

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

MSBuild tasks that write to System.Console bypass 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 to Log. Failures are unaffected; the task already checks ExitCode and calls LogError.
  • PublishBuildToMaestro — four ##vso commands moved to Log.LogMessage(High). They still reach the agent: Command.TryParse finds the prefix with IndexOf, not StartsWith (there's a unit test for ">>> ##vso[...]"), so the logger's indentation doesn't matter. The same file already emits artifact.upload this way 30 lines earlier, as does PushToBuildStorage.
  • GenAPITask — GetOutput returned Console.Out when no OutputPath was set; it now buffers a line at a time into Log. Lines are passed with no format arguments, since generated C# is full of braces.

Console usage elsewhere is left alone — PipelinesLogger is an ILogger, Helix JobMonitor is a standalone tool, and the rest are CLI entry points or tests.

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.
Copilot AI lite review requested due to automatic review settings August 26, 2026 18:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: forward dotnet-install stdout/stderr to Log.LogMessage and adjust importance for the “already installed” notice.
  • PublishBuildToMaestro: emit Azure Pipelines ##vso[...] commands via Log.LogMessage instead of Console.WriteLine.
  • GenAPITask: default output now goes to the build log via a TextWriter that forwards generated output line-by-line to Log.
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

@ViktorHofer
ViktorHofer enabled auto-merge (squash) August 26, 2026 18:58
@ViktorHofer
ViktorHofer merged commit 77ae37d into dotnet:main Aug 26, 2026
9 of 12 checks passed
@ViktorHofer
ViktorHofer deleted the console-to-build-log branch August 26, 2026 20:01
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 28, 2026
ViktorHofer added a commit to ViktorHofer/arcade that referenced this pull request Aug 28, 2026
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
@JanProvaznik

Copy link
Copy Markdown
Member

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 release/11.0, which does not contain that change.

The public pinned sources show the regression:

Arcade version Commit BAR tag and pipeline-variable commands
11.0.0-beta.26456.1 66b75e61d8 Log.LogMessage(MessageImportance.High, ...)
11.0.0-beta.26469.4 c34a902ee9 Console.WriteLine(...)
11.0.0-beta.26501.5 a6e43f8532 Console.WriteLine(...)

PublishBuildToMaestro is declared with Runtime="NET" and Architecture="*". When it runs in an external task host, direct console writes are not a reliable way to deliver Azure Pipelines logging commands to the invoking agent. The BAR registration can succeed while the BARBuildId, DefaultChannels, and IsStableBuild variables are never set. The subsequent Create ReleaseConfigs Artifact step then receives literal $(BARBuildId), which PowerShell interprets as a command invocation and fails with BARBuildId not recognized.

The fix is to backport the publishing-command changes from #17412 to release/11.0 and consume the resulting Arcade build. Restoring the known-good Arcade pin is an alternative workaround. The source comparison identifies a concrete Arcade regression; it does not establish that the accompanying .NET SDK update needs to be reverted.

@JanProvaznik

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants