问题描述
背景:我管理着一个相当大的解决方案.每隔一段时间,人们就会在他们应该添加项目引用的解决方案中添加对项目的 DLL 引用.我想在这种情况下发出警告.我想通过在他们的 HintPath* 中找到所有带有 'bindebug' 的引用来做到这一点.我知道引用是 ItemGroup 中的项目,元数据为HintPath".
Background: I manage a fairly large solution. Every so often, people add a DLL reference to a project in the solution where they should've added a project reference. I want to issue a warning in such case. I want to do it by finding all reference with 'bindebug' in their HintPath*. I know that references are Items in ItemGroup, with metadata "HintPath".
我希望这样的事情能奏效:
I expected something like this to work:
<Warning Text="Reference %(Reference.Identity) should be a project reference. HintPath: %(Reference.HintPath)"
Condition="%(Reference.HintPath).IndexOf('bindebug') != -1"/>
但是,似乎我不能像那样使用字符串函数 IndexOf.我尝试了上述的许多排列,但没有成功.
However, Seems like I can't use string function IndexOf like that. I tried many permutations of the above, without success.
- 我知道这个检查不是完全证明,但我只是想减少诚实的错误.
推荐答案
使用 MSBuild 4.0 属性函数 可以进行字符串比较:
Using MSBuild 4.0 Property Functions it is possible to do string comparisons:
<Target Name="AfterBuild">
<Message Text="Checking reference... '%(Reference.HintPath)'" Importance="high" />
<Warning Text="Reference %(Reference.Identity) should be a project reference. HintPath: %(Reference.HintPath)"
Condition="$([System.String]::new('%(Reference.HintPath)').Contains('in$(Configuration)'))" />
</Target>
这篇关于对元数据值使用 Item 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!