Take the 2-minute tour ×

I have a MSBuild script to copy specific files from source to destination like given below. I dont want to give *.txt but give file names because I want only these files. Here the directory "E:\Test100\" is repeated for multiple times (I can put it in a property, but still the property will be repeated).

Is there a way to simplify this to refer to these files from the specific directory which is defined once?

  <Target Name="CopyAllFiles">
    <ItemGroup Label="FilesToCopy">
      <File Include="E:\Test100\1.txt"/>
      <File Include="E:\Test100\2.txt"/>
      <File Include="E:\Test100\3.txt"/>
      <File Include="E:\Test100\4.txt"/>
      <File Include="E:\Test100\5.txt"/>
      <File Include="E:\Test100\6.txt"/>
      <File Include="E:\Test100\7.txt"/>
      <File Include="E:\Test100\8.txt"/>
    <Copy SourceFiles="@(File)"

Note: MSBuild script and files are in different directories.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Have a look at documentation about msbuild batching/list ttransformation etc. What you want is the typical way msbuild can deal with lists - if you want to keep repetition to a minimum, you wouldn't even have to specify the .txt part:

<ItemGroup Label="FilesToCopy">
  <FileName Include="1"/>
  <FileName Include="2"/>
  <FileName Include="3"/>
  <FileName Include="4"/>
  <FileName Include="5"/>
  <FileName Include="6"/>
  <FileName Include="7"/>
  <FileName Include="8"/>
  <File Include="E:\Test100\%(FileName.Identity).txt"/>
share|improve this answer
Thank you, It works... –  Sanketh P B Apr 6 at 8:56

Your Answer


