Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild combine files

Tags:

msbuild

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.
like image 218
chezy525 Avatar asked Mar 23 '12 20:03

chezy525


2 Answers

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).

like image 109
KMoraz Avatar answered Oct 18 '22 13:10

KMoraz


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.

like image 44
heavyd Avatar answered Oct 18 '22 13:10

heavyd