如何将数据传递给 MSBuild 任务的 ITaskItem 属性? [英] How to pass data to an ITaskItem property of an MSBuild task?
问题描述
我有一个在 MSBuild 中使用的自定义任务.效果很好.以前,我有一些属性接受一些 string
数据.有人建议我应该将它们更改为 ITaskItem
的.这样,如果我有空格,我应该不会有问题.
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.
public class CompressorTask : Task
{
....
public string CssFiles { get; set; }
public string JavaScriptFiles { get; set; }
}
示例 msbuild 文件(例如 MsBuildSample.xml)...
example msbuild file (eg. MsBuildSample.xml)...
<CompressorTask
CssFiles="StylesheetSample1.css, StylesheetSample2.css,
StylesheetSample3.css, StylesheetSample4.css"
JavaScriptFiles="jquery-1.2.6-vsdoc.js"
... />
注意到我有 4 个 css 文件吗?我通过 , 或空格分隔符手动提取它们.凯尔.
Notice how i've got 4 css files? i manually extracted them by the , or space delimeter. Kewl.
public ITaskItem[] CssFiles { get; set; }
public ITaskItem[] JavaScriptFiles { get; set; }
现在,我不确定我需要在 MSBuild 文件的 CssFiles 属性中设置什么值.
Now, i'm not sure what values i need to set, in the CssFiles property, in the MSBuild file.
有什么建议吗?
推荐答案
我认为您现在需要将文件放入带有属性名称的项目列表中:
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)"/>
这篇关于如何将数据传递给 MSBuild 任务的 ITaskItem 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!