Possible to reverse order of ItemGroup elements?

Posted by Filburt on Stack Overflow See other posts from Stack Overflow or by Filburt
Published on 2010-06-14T11:18:50Z Indexed on 2010/06/14 11:22 UTC
Read the original article Hit count: 289

Filed under:

In MSBuild 3.5, is it possible to reverse the order elements in an ItemGroup?

Example

I have 2 projects. One can be built independently the other is dependent on the first. Each project references its specific items in a .targets file.

project_A.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <AssembliesToRemove Include="@(AssembliesToRemove)" />
        <AssembliesToRemove Include="Assembly_A.dll">
            <ApplicationName>App_A</ApplicationName>
        </AssembliesToRemove>
    </ItemGroup>

    <ItemGroup>
        <AssembliesToDeploy Include="@(AssembliesToDeploy)" />
        <AssembliesToDeploy Include="Assembly_A.dll">
            <AssemblyType>SomeType</AssemblyType>
            <ApplicationName>App_A</ApplicationName>
        </AssembliesToDeploy>
    </ItemGroup>
</Project>

project_B.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <AssembliesToRemove Include="@(AssembliesToRemove)" />
        <AssembliesToRemove Include="Assembly_B.dll">
            <ApplicationName>App_B</ApplicationName>
        </AssembliesToRemove>
    </ItemGroup>

    <ItemGroup>
        <AssembliesToDeploy Include="@(AssembliesToDeploy)" />
        <AssembliesToDeploy Include="Assembly_B.dll">
            <AssemblyType>SomeType</AssemblyType>
            <ApplicationName>App_B</ApplicationName>
        </AssembliesToDeploy>
    </ItemGroup>
</Project>

project_A.proj

<Project DefaultTargets="Start" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="project_A.targets" />

    <Import Project="Common.targets" />
</Project>

project_B.proj

<Project DefaultTargets="Start" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="project_A.targets" />

    <Import Project="project_B.targets" />

    <Import Project="Common.targets" />
</Project>

The Problem

In this scenario the problem arises during the Task processing @(AssembliesToDeploy) because Assembly_B.dll needs to be deployed before Assembly_A.dll.

What I tried to do

I tried to influence the order of @(AssembliesToDeploy) by modifying project_B.targets like this:

<ItemGroup>
    <AssembliesToDeploy Include="Assembly_B.dll">
        <AssemblyType>SomeType</AssemblyType>
        <ApplicationName>App_B</ApplicationName>
    </AssembliesToDeploy>
    <AssembliesToDeploy Include="@(AssembliesToDeploy)" />
</ItemGroup>

but when using project_B.targets inside project_B.proj the order inside @(AssembliesToDeploy) still remained Assembly_A.dll;Assembly_B.dll.

Is there a solution which would allow to reuse my .targets i.e not copying all ItemGroup elements to all .targets files?

© Stack Overflow or respective owner

Related posts about msbuild