如果 ItemGroup 包含项目,如何进行 MSBuild 条件测试?
这应该很简单,但我找不到如何做到这一点(或者也许这是不可能的)。
在 MSBuild 中,我有一个 ItemGroup,它是文件列表。 我只想在特定文件位于该 ItemGroup 中时才执行任务,
例如:
<Copy Condition="@(Files) <contains> C:\MyFile.txt" .... />
有什么方法可以做到这一点吗?最好不编写自定义任务。
编辑:文件列表仅与条件有关。否则与任务无关。
This should be simple, but I can't find how to do this (or maybe it's not possible).
In MSBuild I have an ItemGroup that is a list of files.
I want to execute a task only if a particular file is in that ItemGroup
Something like:
<Copy Condition="@(Files) <contains> C:\MyFile.txt" .... />
Any way to do this? Preferably without writing a custom task.
Edit: The list of files is only to do with the condition. Otherwise it has no relation to the task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
我遇到了类似的问题,如果文件未包含在 itemGroup 中,我想做一些事情。就我而言,它是
项组。此代码片段扫描标记中的所有文件,对于每个文件,如果文件的 FullPath 与
TheFileIAmLookingFor
匹配,则我设置一个属性来指示已找到该文件。然后我可以使用该属性,如果未设置该属性,我可以假设该项目未包含在
项目组中。就我而言,最后的操作是仅在项目不存在时才添加该项目。对于上下文,我在通过自定义 msbuild 构建任务进行代码生成时遇到了这个问题,并且生成的代码有时会被引用两次,这会引发警告。I had a similar issue, where I wanted to do something if a file was not included in an itemGroup. In my case, it was the
<Compile>
item group.This snippet is scanning through all the files in the tag, and for each one, if the file's FullPath matches the
TheFileIAmLookingFor
, then I set a property indicating the file was found.Then I can use that property, and if it isn't set, I can assume the item wasn't included in the
<Compile>
item group. In my case, the final action is to add the item only if it didn't exist. For context, I came across this issue while working on code-generation via custom msbuild build tasks, and the generated code was sometimes getting referenced twice, which was throwing a warning.