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 4114218
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:25:38+00:00 2026-05-20T22:25:38+00:00

I would like to use the MSBuild task in my target in order to

  • 0

I would like to use the “MSBuild” task in my target in order to build another project, while passing some items (with their metadata) from the current project to the project to be built.
While it’s possible to pass properties using the Properties attribute or the AdditionalProperties Metadata, I couldn’t find a way to pass Items.
A possible solution could be to write the items to a file and pass the filename as a property, but this would pass only the items, without their metadata.

Any idea?

Thanks.

  • 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-20T22:25:39+00:00Added an answer on May 20, 2026 at 10:25 pm

    It is fairly straightforward to write a custom task to dump items and their metadata to a file, to be picked up by another process. Instead of just dumping the items in raw text form though, generate a valid MSBuild project file containing the item group (with item meta data) and have that generated file imported by the project being executed by the MSBuild task. You can even use an MSBuild 4.0 inline task to dump the file.

    (response to comment)

    <UsingTask
      TaskName="WriteItemsWithMetadata"
      TaskFactory="CodeTaskFactory"
      AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
      <ParameterGroup>
        <OutputFile ParameterType="System.String" Required="true" />
        <Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
      </ParameterGroup>
      <Task>
        <Using Namespace="System.IO" />
        <Code Type="Fragment" Language="cs">
      <![CDATA[
      // This code simplified with specific knowledge
      // of the item metadata names.  See ITaskItem
      // documentation to enable writing out arbitrary
      // meta data values
      //
      using (StreamWriter writer = new StreamWriter(OutputFile))
      {
        writer.Write("<?");
        writer.WriteLine(" version=\"1.0\" encoding=\"utf-8\"?>");
        writer.WriteLine("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"");
        writer.WriteLine("  ToolsVersion=\"4.0\">");
        writer.WriteLine("  <ItemGroup>");
    
        foreach (var item in Items)
        {
          string meta1 = item.GetMetadata("Meta1");
          string meta2 = item.GetMetadata("Meta2");
          writer.WriteLine("    <CopyItem Include=\"{0}\">", item.ItemSpec);
          writer.WriteLine("      <Meta1>{0}</Meta1>", meta1);
          writer.WriteLine("      <Meta2>{0}</Meta2>", meta2);
          writer.WriteLine("    </CopyItem>");
        }
        writer.WriteLine("  </ItemGroup>");    
        writer.WriteLine("</Project>");    
      }
      ]]>
        </Code>
      </Task>
    </UsingTask>
    
    <ItemGroup>
      <OriginalItem Include="A">
        <Meta1>A1</Meta1>
        <Meta2>A2</Meta2>
      </OriginalItem>
      <OriginalItem Include="B">
        <Meta1>B1</Meta1>
        <Meta2>B2</Meta2>
      </OriginalItem>
    </ItemGroup>
    <Target Name="WriteItemsWithMetadata">
      <WriteItemsWithMetadata
        OutputFile="Out.props"
        Items="@(OriginalItem)"
        />
      <Exec Command="type Out.props" />
    </Target>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We would like to use msbuild to clear the connectionStrings section from a web.config
I'm on a .NET project, and I would like to migrate build script from
I would like to use Sublime Text 2 to build my Visual Studio 2010
I would like my MSbuild build script to be able to detect which server
I have a website project in Visual Studio 2008. I would like to build
I would like to use $a and $b variables in my anonimous binary functions
I would like to use a TextBox for a password, but before the user
I would like to use the Tornado web server to connect to a HTTP
I would like to use the Roboto font in my Android application and make
I would like to use ListBox1.loadfromfile method in .NET, but it doesn't seem to

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.