24

I wanna write <Message Text="Line1\nLine2\nLine3" /> but \n seems not to be working. What should I replace \n with?

(I read in the books they said that to print @ and % we use %40 and %25, so I guess the should be a number for the new-line).

Kyle Trauberman
  • 24,976
  • 13
  • 86
  • 117
Nam G VU
  • 30,868
  • 67
  • 216
  • 353

5 Answers5

44

Try this: <Message Text="Line1%0aLine2%0aLine3%0a" />

Nam G VU
  • 30,868
  • 67
  • 216
  • 353
21

CR = 0x0D or 13

LF = 0x0A or 10

DaveE
  • 3,569
  • 29
  • 30
  • 7
    Thanks DaveE. I try . It works and print out: a bb Thank you. – Nam G VU Mar 17 '10 at 06:42
  • 4
    What a lazy answer, why not include a full example, the answer is actually contained in OP's comment (and other answer). – MarioDS Jun 03 '16 at 12:46
  • 1
    Well, i *could* have done the "throw it up and see if it sticks" answer, or i could explain the values necessary to achieve what the poster wanted and let them apply it themselves. – DaveE Jun 03 '16 at 15:27
1

Here's a better way. Use the "Escape()" property function [1] in a trivial msbuild file like so:

<Message Text="$([MSBuild]::Escape('A\r\nB\r\nC\r\n'))" /> 

The 'Escape()' property function should do all the magic in terms of escaping exotic characters.

[1] https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-escape-special-characters-in-msbuild?view=vs-2017 & https://docs.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2017

Sebastian Krysmanski
  • 7,604
  • 10
  • 46
  • 85
XDS
  • 3,153
  • 2
  • 29
  • 44
1

You could put the lines into an item group

<ItemGroup>
      <Lines Include="Line 1 " />
      <Lines Include="Line 2 " />
      <Lines Include="Line 3 " />
</ItemGroup>

<Message Text="%(Lines.Identity)"/>
Stuart Smith
  • 1,800
  • 14
  • 25
0

Put the multiline message in a property (in the example below called MyMultilineMessage) and then use that property in the message text. (Works at least with MSBuild for VisualStudio 2019)

    <PropertyGroup>
      <MyMultilineMessage>

Lorum ipsum...
      </MyMultilineMessage>
    </PropertyGroup>

    <Message Importance="High" Text="$(MyMultilineMessage)"/>

This also works for Error elements as well.

Edit: Modified XML example above after comment about missing PropertyGroup.

Ermingol
  • 33
  • 4