Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:59:34+00:00 2026-05-15T05:59:34+00:00

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

  • 0

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.

Processing @(AssembliesToRemove) works fine because here the assemblies are in the right order (remove Assembly_A.dll before Assembly_B.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.

Edit

As MadGnome points out this cannot work because I’ll end up with duplicates in @(AssembliesToDeploy)

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:59:35+00:00Added an answer on May 15, 2026 at 5:59 am

    You just have to include project_B.targets before project_A.

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

    I think there is a mistake in this code :

    <ItemGroup>
      <!-- Generates duplicates if used with Import -->
      <AssembliesToDeploy Include="@(AssembliesToDeploy)" />
    
      <AssembliesToDeploy Include="Assembly_B.dll">
        <AssemblyType>SomeType</AssemblyType>
        <ApplicationName>App_B</ApplicationName>
      </AssembliesToDeploy>
    </ItemGroup>
    

    You are using Import, so you if you use the code above you’ll have duplicates in AssembliesToDeploy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
How can I construct a MSBuild ItemGroup to exclude .svn directories and all files
Is it possible to pass a property from one msbuild project to another? So
MSBuild 3.5 I have the following project structure: trunk/MainSolution.sln trunk/Build/MyBuild.Proj trunk/Library/... trunk/etc... So far,
There is a MSBuild script, that includes number if Delphi and C# projects, unit
I'm currently using msbuild for a solution of over 600 projects. Imagine I change
I am creating an MSBuild task that will generate one or more files, I
Is it possible in MSBuild to batch tasks without having the metadata value you
Is it possible to run an msbuild task that populates a property or Item
Is it possible to use an msbuild task to build a smart device project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.