在元数据值上使用Item函数

Jon*_*han 17 msbuild

背景:我管理一个相当大的解决方案.每隔一段时间,人们就会在解决方案中为项目添加DLL引用,他们应该添加项目引用.我想在这种情况下发出警告.我想通过在他们的HintPath*中找到'bin\debug'的所有引用来做到这一点.我知道引用是ItemGroup中的项目,元数据为"HintPath".

我期待这样的事情发挥作用:

<Warning Text="Reference %(Reference.Identity) should be a project reference. HintPath: %(Reference.HintPath)"
         Condition="%(Reference.HintPath).IndexOf('bin\debug') != -1"/>
Run Code Online (Sandbox Code Playgroud)

但是,似乎我不能像这样使用字符串函数IndexOf.我尝试了上述的许多排列,没有成功.

  • 编辑:我知道这个检查不是完全证明,但我只是想减少诚实的错误.

KMo*_*raz 21

使用MSBuild 4.0 属性函数可以进行字符串比较:

<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>
Run Code Online (Sandbox Code Playgroud)