100

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?

1
  • 2
    I recently found and used the possibility to debug MSBuild with Visual Studio - including breakpoints, variable inspection, and stuff. It's amazingly helpful with complicated build projects. (You need to modify the registry to enable the undocumented /debug switch in MSBuild which lets you attach a debugger upon build start) Commented Dec 29, 2021 at 20:32

4 Answers 4

126

Add the Importance attribute with value High to Message.

Like this:

<Message Importance="High" Text="+++ Justin Dearing +++" />
Sign up to request clarification or add additional context in comments.

Comments

52

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.

1 Comment

Another idea is to set the Condition parameter of the Message task so that it is of high importance when in Debug mode but low when in Release.
46

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>

1 Comment

Instead of InitialTargets at project level, also you can explicitly specify before or after each existing target it should be executed. Like <Target Name="Test" AfterTargets="AfterBuild">
6

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.