Question

I want to run a custom task to compile .less files to .css before packaging the application (.net mvc 3).

I don't have a lot of experience creating MSBUILD scripts so by reading online I came up with code below. It works, but I feel like there should be a way for me to skip the ItemGroup explicit declaration and just instruct the script to look for 'any folder under Skins folder'. Is that possible at all?

  <Target Name="CompileLessToCss" BeforeTargets="Package">
  <PropertyGroup>
    <DotLessCompiler>..\..\Libraries\dotless\dotless.Compiler.exe</DotLessCompiler>        
    <!--Skin Paths -->
    <ApplicationSkins>Content\Skins\</ApplicationSkins>
    <MobileSkins>Areas\Mobile\Content\Skins\</MobileSkins>
    <!--Style FileNames -->
    <LessPath>\less\main.less</LessPath>
    <CssPath>\css\main.min.css</CssPath>
  </PropertyGroup>
<ItemGroup>
  <Skins Include="$(ApplicationSkins)Blue"/>
  <Skins Include="$(MobileSkins)Blue"/>
  <Skins Include="$(ApplicationSkins)Red"/>
  <Skins Include="$(MobileSkins)Red"/>
  <Skins Include="$(ApplicationSkins)Yellow"/>
  <Skins Include="$(MobileSkins)Yellow"/>
</ItemGroup>

<!-- Compiling Less Files -->
<Message Text="Compiling Less For Skins: @(Skins)"/>
<Exec Command="$(DotLessCompiler) -m &quot;%(Skins.FullPath)$(LessPath)&quot; &quot;%(Skins.FullPath)$(CssPath)&quot;" />

Was it helpful?

Solution

You can construct the item group using wildcards. Something along these lines:

 <ItemGroup><skins Include=".\Skins\*"></Itemgroup>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top