导入元素无法正确展开ItemGroup

时间:2018-12-27 16:42:48

标签: msbuild msbuild-itemgroup

我正在尝试使用目录基名称填充ItemGroup,将其传递通过转换以从中创建绝对路径,然后导入驻留在那里的文件。它在Message元素中可以正常工作,但在Import中却无能为力。我想念什么?

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <MyDependencies Include="Dir1" />
        <MyDependencies Include="Dir2" />
    </ItemGroup>

    <!-- "Expansion: C:\path\Dir1\import.targets;C:\some\path\Dir2\import.targets" -->
    <Target Name="TestMessage" BeforeTargets="PrepareForBuild">
        <Message
            Importance="High"
            Text="Expansion: @(MyDependencies -> 'C:\path\%(Identity)\import.targets')"
        />
    </Target>

<!-- Uncomment to trigger error -->
<!--<Import Project="@(MyDependencies -> 'C:\path\%(Identity)\import.targets')" />-->
</Project>

Import的路径未扩展,并导致:

error MSB4102: The value "@(MyDependencies -> 'C:\path\%(Identity)\import.targets')" of the "Project" attribute in element <Import> is invalid. Illegal characters in path.

0 个答案:

没有答案