How do I get the <Message> MSBuild task to show up in the Visual Studio project output?

Visual StudioMsbuild

Visual Studio Problem Overview


I'm trying to printf debug my Visual Studio project file by spewing messages to the console like this:

<Target Name="BeforeBuild">
  <Message Text="+++++++++++++++++++++++ Justin Dearing ++++++++++++++++++++++++++++++++++++" />
</Target>

This works from the command line:

BeforeBuild:
  +++++++++++++++++++++++ Justin Dearing ++++++++++++++++++++++++++++++++++++

However, the messages don't show up in the Visual Studio 2010 build output. Is there an alternative MSBuild task I can use, or a setting in Visual Studio I can enable to make these messages appear?

Visual Studio Solutions


Solution 1 - Visual Studio

Add the Importance attribute with value High to Message.

Like this:

<Message Importance="High" Text="+++ Justin Dearing +++" />

Solution 2 - Visual Studio

To change the build output verbosity shown in the Visual Studio 2010 window, open the Options dialog and select the Build and Run settings below the Projects and Solutions node.

Unless you explicitly specify a low message importance, your messages should show up at Normal verbosity or higher.

Solution 3 - Visual Studio

For anyone reading this with MSBuild 16, bear in mind that you can't use message at the project level. You now need to first define InitialTargets

<Project InitialTargets="Test" ...

And then create a task to place the message in:

  <Target Name="Test">
      <Message Importance="High" Text="A Message" />
  </Target>

Solution 4 - Visual Studio

In VisualStudio 2019 a <Message> disappears from Build log if any <Error> Task occurs in "Build" target (and others?) even if <Error> is after <Message>.

In contrast msbuild.exe 16.8.2.56705 displays <Message> in any case.

[Question only implies by example that BeforeBuild is used, I answered anyway as the question title and text perfectly matched my problem that the message was not shown]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJustin DearingView Question on Stackoverflow
Solution 1 - Visual StudioDevin Gleason LambertView Answer on Stackoverflow
Solution 2 - Visual StudioThomas GerstendörferView Answer on Stackoverflow
Solution 3 - Visual StudioMarco CraveiroView Answer on Stackoverflow
Solution 4 - Visual StudiojifbView Answer on Stackoverflow