25

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
  • 25,414
  • 13
  • 85
  • 121
Nam G VU
  • 33,193
  • 69
  • 233
  • 372

5 Answers5

46

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

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
21

CR = 0x0D or 13

LF = 0x0A or 10

DaveE
  • 3,579
  • 28
  • 31
  • 8
    Thanks DaveE. I try . It works and print out: a bb Thank you. – Nam G VU Mar 17 '10 at 06:42
  • 5
    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://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-escape-special-characters-in-msbuild?view=vs-2017 & https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2017

Sebastian Krysmanski
  • 8,114
  • 10
  • 49
  • 91
XDS
  • 3,786
  • 2
  • 36
  • 56
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,931
  • 15
  • 26
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