MSBuild RecursiveDir is empty

倾然丶 夕夏残阳落幕 提交于 2019-12-13 06:58:37

问题


I'm trying to make a custom MSBuild script to build all solutions in our repository:

<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>

The script works well except for the last copy task where %(RecursiveDir) evaluates to an empty string, putting all files in the root destination folder... I can't see what I'm doing wrong here.

I found MSBuild ITaskItem RecursiveDir metadata disappears but it doesn't seem to apply here...

I also found this and this thread but there are no double slashes or braces in any paths. Heres an example of the output during the copy task:

Copying file from "x:\my\repo\SolutionDir\ProjectDir\bin\Release\Example.dll" to ".\Release\Example.dll".


回答1:


Even though the AllSolutions items have RecursiveDir metadata populated because of the ** wildcard in your code, the MSBuild task is not populating RecursiveDir in the OutputFiles items. The TargetOutputs are placed into a single array, with full paths but no RecursiveDir metadata.



来源:https://stackoverflow.com/questions/26656817/msbuild-recursivedir-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!