在元数据值上使用Item函数 [英] Using Item functions on metadata values

查看:59
本文介绍了在元数据值上使用Item函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我管理的解决方案相当大.人们常常在解决方案中向项目中添加DLL参考,他们应该在其中添加项目参考.在这种情况下,我想发出警告.我想通过在他们的HintPath *中找到所有带有'bin \ debug'的引用来做到这一点.我知道引用是ItemGroup中的Items,其元数据为"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 'bin\debug' 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('bin\debug') != -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('\bin\$(Configuration)'))" />

</Target>

这篇关于在元数据值上使用Item函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆