3

i have a custom Task which i use in MSBuild. Works great. Previously, i had some properties which accepted some string data. It was suggested I should change them to ITaskItem's. This way, if i have spaces, i shouldn't have a problem.

Previous code

public class CompressorTask : Task
    {
    ....
    public string CssFiles { get; set; }
    public string JavaScriptFiles { get; set; }
}

example msbuild file (eg. MsBuildSample.xml)...

<CompressorTask
    CssFiles="StylesheetSample1.css, StylesheetSample2.css, 
              StylesheetSample3.css, StylesheetSample4.css"
    JavaScriptFiles="jquery-1.2.6-vsdoc.js"
... />

Notice how i've got 4 css files? i manually extracted them by the , or space delimeter. Kewl.

New Code

 public ITaskItem[] CssFiles { get; set; }
 public ITaskItem[] JavaScriptFiles { get; set; }

Now, i'm not sure what values i need to set, in the CssFiles property, in the MSBuild file.

any suggestions?

Community
  • 1
  • 1
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

2 Answers2

8

I think you now need to put the files into an itemlist with the name of the property:

<ItemGroup>
    <CssFiles Include="StylesheetSample1.css"/>
    <CssFiles Include="StylesheetSample2.css"/>
    <CssFiles Include="StylesheetSample3.css"/>
    <CssFiles Include="StylesheetSample4.css"/>
    <!-- or <CssFiles Include="*.css" /> -->
    <JavaScriptFiles Include="jquery-1.2.6-vsdoc.js"/>
</ItemGroup>
<CompressorTask CssFiles="@(CssFiles)" JavaScriptFiles="@(JavaScriptFiles)"/>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
3

This is actually way easier, just use a string array. When specifying the values, use a single value, a semi-colon separated list (with whitespace if you like), or an ItemGroup (e.g. @(someItemGroup)), MSBuild is smart enough to figure this out for you:

<CompressorTask
    CssFiles="StylesheetSample1.css; StylesheetSample2.css;
              StylesheetSample3.css; StylesheetSample4.css"
    JavaScriptFiles="jquery-1.2.6-vsdoc.js"
... />

MSBuild task source:

public string[] CssFiles { get; set; }
public string[] JavaScriptFiles { get; set; }
Wedge
  • 19,513
  • 7
  • 48
  • 71