msbuild properties initialized from functions cannot be converted to items?
I am trying to create an msbuild project where dependency information is read from a text file. I have a text file named project.dep which contains a semicolon separated list of project names. In this example the file contains a;b;c;d
I expected the code below to generate two identical item lists:
<PropertyGroup>
<from_file>$([System.IO.File]::ReadAllText($(ProjectName).dep))</from_file>
<inline>a;b;c;d</inline>
</PropertyGroup>
<ItemGroup&g开发者_运维问答t;
<from_file_items Include="$(from_file)" />
<inline_items Include="$(inline)" />
</ItemGroup>
<Target Name="Test">
<Message Text="file: @(from_file_items->'%(filename).item')" />
<Message Text="inline: @(inline_items->'%(filename).item')" />
</Target>
But the result is different:
Test:
file: a;b;c;d.item
inline: a.item;b.item;c.item;d.item
This is not what I expected. I need to map each name in the file to a separate item. Any ideas?
When read from the file, the entire contents is considered a single item, so "a;b;c;d" -- when passed into the item specification when @(from_file_items) is defined -- isn't being split up the same way it is when passed to @(inline_items). MSBuild is escaping the value, you need to unescape it.
Change this:
<from_file_items Include="$(from_file)" />
to this:
<from_file_items Include="$([MSBuild]::Unescape($(from_file)))" />
精彩评论