chezy525
chezy525

Reputation: 4174

MSBuild combine files

I'm trying to combine all javascript files in a project during the build process, but it just isn't working for me. Here's what I have:

<Target Name="CombineJS">
  <CreateItem Include=".\**\*.js">
    <Output TaskParameter="Include" ItemName="jsFilesToCombine" />
  </CreateItem>

  <ReadLinesFromFile File="@(jsFilesToCombine)">
    <Output TaskParameter="Lines" ItemName="jsLines" />
  </ReadLinesFromFile>

  <WriteLinesToFile File="all.js" Lines="@(jsLines)" Overwrite="true" />
</Target>

MSBuild is throwing an error on the ReadLinesFromFile line saying there's an invalid value for the "File" parameter. (No error when there's only one file to combine)

So, two questions:

  1. What am I doing wrong?
  2. Is there a better way to combine files within an MSBuild task? I ask this question because I know that my current process removes all tabs and blank lines, which for me isn't that big of a deal, but still kind of annoying.

Upvotes: 10

Views: 3410

Answers (2)

KMoraz
KMoraz

Reputation: 14164

Change line 6 to:

<ReadLinesFromFile File="%(jsFilesToCombine.FullPath)">

The @ operator is used when the input is ItemGroup which is essentially a semicolon-delimited list of strings.

The % operator is for expanding ItemGroups into strings (properties).

Upvotes: 15

heavyd
heavyd

Reputation: 17731

The ReadLinesFromFileTask you are using to read the files takes a single file as input to the File property (MSDN). You can't use this task to read lines from multiple files at once. You may however be able to use batching to run the task several times for each file.

Upvotes: 2

Related Questions