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

  • Home
  • SEARCH
  • 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 7180889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:26:35+00:00 2026-05-28T17:26:35+00:00

I am trying to write MSBuild script that will perform some action (eg. print

  • 0

I am trying to write MSBuild script that will perform some action (eg. print its path) on an arbitrary files (specified as a property on a command line) in some predefined directory (F:\Files).

Given the following directory structure

F:\Files\TextFile.txt
F:\Files\Subdir1\ImageFile.bmp
F:\Files\Subdir1\SubSubdir\ImageFile2.bmp
F:\Files\Subdir1\SubSubdir\TextFile2.txt

And MSBuild Script

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="PrintNames" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TargetDir>F:\Files</TargetDir>
    </PropertyGroup>

    <ItemGroup>
        <Files Include="$(TargetDir)\$(InputFiles)"/>
    </ItemGroup>

    <Target Name="PrintNames">
        <Message Text="Files: @(Files, ', ')" />
    </Target>
</Project>

running the script with InputFiles set to “**\*.bmp;**\*.txt” works fine only for bmp files. Txt files are taken from the current working directory, not from “F:\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-28T17:26:36+00:00Added an answer on May 28, 2026 at 5:26 pm

    There are two problems that you have to solve:

    1. $(InputFiles) is specifed as a scalar property, but you want to interprete it as an array
    2. $(InputFiles) contains wildcards you want to expand after you do transformation on the list of patterns in $(InputFiles).

    It is easy to solve either of two problems separately, but combination of the two is actually tricky. I have one possible solution, and it works, but the downside is you have to encode ‘*’ characters in your pattern definition.

    <?xml version="1.0" encoding="utf-8"?> 
    <Project ToolsVersion="4.0" DefaultTargets="PrintNames" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
      <PropertyGroup> 
        <TargetDir>c:\temp\MyContent</TargetDir> 
        <InputFilesRelativeEsc>%2A%2A\%2A.bmp;%2A%2A\%2A.txt</InputFilesRelativeEsc>
      </PropertyGroup> 
    
      <Target Name="PrintNames"> 
        <ItemGroup>
            <_TempGroup Include="$(InputFilesRelativeEsc)" />
        </ItemGroup>
    
        <CreateItem Include="@(_TempGroup->'$(TargetDir)\%(Identity)')"> 
            <Output TaskParameter="Include" ItemName="_EvaluatedGroup" /> 
        </CreateItem> 
        <Message Text="_EvaluatedGroup: %(_EvaluatedGroup.FullPath)" />
    
      </Target> 
    </Project> 
    

    It works as follows. Property InputFilesRelativeEsc is a list of relative file patterns. Notice wildcard characters are encoded (%2A is a hex code for asterisk). Since the wildcards encoded, the group _TempGroup does not attempt to search for and extract list of files while you Include this patterns into this group. Now _TempGroup is a group which consists of two elements: **\*.bmp and **\*.txt. Now that you have a real group you can transform it. The only complication is that the normal MSBuild mechanism of running transform does not expand wildcards. You have to use older CreateItem task. The CreateItem task is actually declared deprecated by MSBuild team, but it still works.

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

Sidebar

Related Questions

I'm trying to write an MsBuild script to zip some files up. I need
I'm trying write a simple perl script that reads some fields from a password
I'm trying to write a MSBuild project that will generate html documentation using doxygen.
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
Trying to write a couple of functions that will encrypt or decrypt a file
im trying to write an app that will display a list off lines from
I'm working with csproj files, and I'm trying to write a cmdlet that extracts
I am trying to write a python script that checks out a revision from
I'm trying to write a MSBuild Task that deletes the Obj directory and PDBs
I'm trying write a routine in SQL Server that, when run, would traverse specified

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.