.NET Framework Developer Center > .NET Development Forums > MSBuild > Trouble making ItemGroup Tags work
Ask a questionAsk a question
 

AnswerTrouble making ItemGroup Tags work

  • Friday, March 06, 2009 11:33 PMKoombah Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I've been getting an error lately that really puzzles me, as it appears to be a part of MSBuild that violates its own schema...

    If a project file is supposed to be an XML file based off of the standard Microsoft MSBuild XML schema, how can the system accept any given name as the title of an ItemGroup?  For example, if I try writing my own file, and use IntelliSense to determine what elements are valid, "ProjectFiles", or "Compile", or even "Bob", is not a viable option under ItemGroup.

    I ask because this is just the problem I'm having with a very rudimentary file, as shown below.  When I try running MSBuild on this XML, I get the error shown (with command)...
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
        <Target Name="Clean">  
            <ItemGroup> 
                <Compile Include="Authentication.dll"/>  
            </ItemGroup> 
            <Delete Files="@(Compile)" /> 
        </Target> 
    </Project> 


    C:\Working Copy\MBIntranet\CommonObjects>msbuild Clean.xml
    Microsoft (R) Build Engine Version 2.0.50727.1433
    [Microsoft .NET Framework, Version 2.0.50727.1433]
    Copyright (C) Microsoft Corporation 2005. All rights reserved.

    Build started 3/6/2009 5:09:06 PM.
    __________________________________________________
    Project "C:\Working Copy\MBIntranet\CommonObjects\Clean.xml" (default targets):

    Target Clean:
      C:\Working Copy\MBIntranet\CommonObjects\Clean.xml(4,4): error MSB4067: The el
    ement <Compile> beneath element <ItemGroup> is unrecognized.
    Done building target "Clean" in project "Clean.xml" -- FAILED.

    Done building project "Clean.xml" -- FAILED.

    Build FAILED.
    C:\Working Copy\MBIntranet\CommonObjects\Clean.xml(4,4): error MSB4067: The elem
    ent <Compile> beneath element <ItemGroup> is unrecognized.
        0 Warning(s)
       
    1 Error(s)

    It looks to me like MSBuild is choking on the violation of the MSBuild XML schema.  If that's the case, how can the given syntax for naming item groups work? 

    Thanks

    -Koombah

Answers

  • Saturday, March 07, 2009 9:54 AMOsirisJakob Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    You are usng a feature called dynamic item groups, which was introduced in MSBuild 3.5. This allows you to put item groups inside a target. However, since
    you are running MSBuild 2.0 this gives you the error.

    Regards
    /Jakob
    • Marked As Answer byKoombah Monday, March 09, 2009 3:32 PM
    •  

All Replies

  • Saturday, March 07, 2009 9:54 AMOsirisJakob Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    You are usng a feature called dynamic item groups, which was introduced in MSBuild 3.5. This allows you to put item groups inside a target. However, since
    you are running MSBuild 2.0 this gives you the error.

    Regards
    /Jakob
    • Marked As Answer byKoombah Monday, March 09, 2009 3:32 PM
    •  
  • Sunday, November 01, 2009 2:11 PMcapt edgar Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    how can we still get this working if we have MSBuild 2 and VS2005 only

  • Sunday, November 01, 2009 5:23 PMMike FourieModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Move the itemgroup outside of the target or use CreateItem within a target.

    Mike
  • Sunday, November 01, 2009 10:26 PMcapt edgar Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Mike

    ANy chance you can show me the syntax please?

    my code looks like this

    <?xml version="1.0" encoding="utf-8" ?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

     <Target Name="Clean">
       <ItemGroup>
           <BinFiles Include="Project A\bin\*.*" />
                   <BinFiles Include="Project B\bin\*.*" />
                   <BinFiles Include="Project C\bin\*.*" />
                   <BinFiles Include="Project D\bin\*.*" />


      </ItemGroup>
       <Delete Files="@(BinFiles)" />
     </Target>
    </Project>

    when i run this using command prompt and entering msbuild Build.xml /t:Clean

    I get an MSB4067 error and an error message saying Workspace\Build.xml (4,1): error MSB4067:
    The element <BinFiles> beneath element <Project> is unrecognized.