Search code examples
cssmsbuildmsbuild-taskdotless

dotless: how to process a list of LESS files using dotless.Compiler.exe


I wanted to know how to process a list of LESS files using the exe binaries, for example:

./dotless.Compiler.exe -m *.less

Right now I only can do individual files, but can't do wildcard.

The reason why I asked about this is that I want to create a target in MSBuild, which is to process an item collection (which is a list of files). I couldn't find a way to loop a task in side MSBuild. If anyone knows how to loop a task for each file, that would solve my problem too.


Solution

  • Use an ItemGroup to get a list of files like this:

    <ItemGroup>
        <MyFiles Include="[path to less files]\*" />
    </ItemGroup>
    

    Call the compiler once for each file by using %(MyFiles.FullPath) syntax (also known as Task Batching)

    <Target Name="CompileLess">
       <Exec Command="$(dotLessCompiler) -m %(MyFiles.FullPath)" />
    </Target>