Beware % in MSBuild

Here is a very basic example:

<Project DefaultTargets="Full" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Ingredients Include="0%Good"/>
<Ingredients Include="100%Bad"/>
</ItemGroup>
<Target Name="Full">
<Message Text="%(Ingredients.Identity)"/>
</Target>
</Project>

It’s a simple cycle through a collection and showing a message. If you think the output is

0%Good
100%Bad

then you would be wrong. It is in fact:

0%Good
100ºd

MSBuild uses the % character to show the beginning of an escaped character. You can get more details here. In this example, you would need to use <Ingredients Include="100%25Bad"/> to display the result you were expecting.

Advertisements
This entry was posted in MSBuild. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s