MSBuild RecursiveDir为空

时间:2014-10-30 15:16:38

标签: msbuild copy msbuild-4.0

我试图制作一个自定义MSBuild脚本来在我们的存储库中构建所有解决方案:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <SourceHome Condition=" '$(SourceHome)'=='' ">..\</SourceHome>
        <ToolsHome Condition=" '$(ToolsHome)'=='' ">.\Tools\</ToolsHome>
        <Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
        <DestFolder Condition=" '$(DestFolder)'=='' ">.\$(Configuration)\</DestFolder>
    </PropertyGroup>

    <ItemGroup>
        <AllSolutions Include="$(SourceHome)**\*.sln"/>
    </ItemGroup>

    <Target Name="Default" DependsOnTargets="Clean;Build;Assemble"/>

    <Target Name="Clean">
        <Message Text="Cleaning projects..."/>
        <MSBuild Projects="@(AllSolutions)"
             Targets="Clean"
             Properties="Configuration=$(Configuration);"/>
    </Target>

    <Target Name="RestorePackages">
        <Message Text="Restoring packages..."/>
        <Exec Command="echo y| &quot;$(ToolsHome)NuGet\NuGet.exe&quot; restore &quot;%(AllSolutions.Identity)&quot;"/>
    </Target>

    <Target Name="Build" DependsOnTargets="RestorePackages">
        <Message Text="Building projects..."/>
        <MSBuild Projects="@(AllSolutions)"
                 ContinueOnError="true"
                 Properties="Configuration=$(Configuration)">
            <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
        </MSBuild>
    </Target>

    <Target Name="Assemble">
        <Message Text="Assembling output..."/>
        <RemoveDir Directories="$(DestFolder)"/>
        <Copy SourceFiles="@(OutputFiles)"
              DestinationFiles="@(OutputFiles->'$(DestFolder)%(RecursiveDir)%(Filename)%(Extension)')"/>
    </Target>
</Project>

该脚本运行良好,除了最后一个复制任务,其中%(RecursiveDir)计算为空字符串,将所有文件放在根目标文件夹中...我无法看到我做错了什么这里。

我找到了MSBuild ITaskItem RecursiveDir metadata disappears,但它似乎并不适用于此......

我还发现了thisthis线程,但在任何路径中都没有双斜线或大括号。下面是复制任务期间输出的示例:

  

从中复制文件   &#34; X:\我的\回购\ SolutionDir \ PROJECTDIR \ BIN \发布\ Example.dll&#34;至   &#34; \发布\ Example.dll&#34;

1 个答案:

答案 0 :(得分:1)

即使AllSolutions项由于代码中的**通配符填充了RecursiveDir metadataMSBuild task也没有填充RecursiveDir OutputFiles 1}}项目。 TargetOutputs被放置在一个数组中,包含完整路径但没有RecursiveDir元数据。