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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:42:08+00:00 2026-05-20T10:42:08+00:00

This seems like it should be simple but I can’t work it out from

  • 0

This seems like it should be simple but I can’t work it out from the reference and my google-fu is apparently weak.

I just want to specify the file names and base folder separately in the build file…

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TestFilesWithFolder>
      B:\Root\Test1.*;
      B:\Root\Test2.*
    </TestFilesWithFolder>
    <TestFiles>Test1.*;Test2.*</TestFiles>
    <TestFileRoot>B:\Root</TestFileRoot>
  </PropertyGroup>
  <Target Name="Build">
    <ItemGroup>
      <TestFilesGroupWithFolder Include="$(TestFilesWithFolder)" />
      <TestFilesGroup Include="$(TestFileRoot)\$(TestFiles)" />
    </ItemGroup>
    <Warning Text="Source files with folder: @(TestFilesGroupWithFolder)" />
    <Warning Text="Source files: @(TestFilesGroup)" />
  </Target>
</Project>

When I run this, the first warning shows both files as expected, but the second warning only shows the first file (since the straight string concat put the folder name on the first but not second).

How would I get the ItemGroup “TestFilesGroup” to include both the files given the “TestFiles” and “TestFileRoot” properties?

  • 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-20T10:42:09+00:00Added an answer on May 20, 2026 at 10:42 am

    It is possible to convert a semicolon delimited list of things into an item, which would make this possible, except that the items in your property contain wildcards, so if you want to have MSBuild treat them as items in a list, at the moment MSBuild first sees it the path must be valid. There may be a way to do that but I can’t think of one. In other words…

    <ItemGroup>
        <TestFiles Include="$(TestFiles)" />
    </ItemGroup>
    

    …only works if $(TestFiles) contains a delimited list of either things with no wildcards, or qualified paths that actually exist.

    Further, MSBuild can’t compose a path with a wildcard inside the Include attribute and evaluate it at the same time, so you need a trick to first compose the full path separately, then feed it into the Include attribute. The following will work, but it requires changing your delimited property into a set of items. It batches a dependent target on this item list, with each batched target execution calculating a meta value for one item, which is stored off in a new meta value. When the original target executes, it is able to use that meta value in a subsequent Include.

    <PropertyGroup>
      <TestFilesWithFolder>
        D:\Code\Test1.*;
        D:\Code\Test2.*
      </TestFilesWithFolder>
      <TestFileRoot>D:\Code</TestFileRoot>
    </PropertyGroup>
    <ItemGroup>
      <TestFilePattern Include="TestFilePattern">
        <Pattern>Test1.*</Pattern>
      </TestFilePattern>
      <TestFilePattern Include="TestFilePattern">
        <Pattern>Test2.*</Pattern>
      </TestFilePattern>
    </ItemGroup>
    <Target Name="Compose" Outputs="%(TestFilePattern.Pattern)">
      <ItemGroup>
         <TestFilePattern Include="TestFilePattern">
            <ComposedPath>@(TestFilePattern->'$(TestFileRoot)\%(Pattern)')</ComposedPath>
         </TestFilePattern>
      </ItemGroup>
    </Target>
    <Target Name="Build" DependsOnTargets="Compose">
      <ItemGroup>    
        <TestFilesGroupWithFolder Include="$(TestFilesWithFolder)" /> 
      </ItemGroup>
      <Warning Text="Source files with folder: @(TestFilesGroupWithFolder)" />
      <ItemGroup>
        <ComposedTestFiles Include="%(TestFilePattern.ComposedPath)" />   
      </ItemGroup>
      <Warning Text="Source files: @(ComposedTestFiles)" />
    </Target>
    

    Which produces the following output:

    (Build target) ->
    d:\Code\My.proj(80,5): warning : Source files with folder:
       D:\Code\Test1.txt;D:\Code\Test2.txt
    d:\Code\My.proj(84,5): warning : Source files:
       D:\Code\Test1.txt;D:\Code\Test2.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.