Is there any MSbuild task to check if a string contains another string (similar to string.contains)

拈花ヽ惹草 提交于 2019-12-17 16:24:34

问题


I have this Msbuild code:

<Import Project="A.proj" Condition="$(BuildDefinition) =='Dist Staging to Dev' Or $(BuildDefinition) =='Dist Staging to Dev(Services Only)'"/>

But I was wondering if is there anything similar to check if an string contains some text to get something similar to:

<Import Project="A.proj" Condition="$(BuildDefinition) CONTAINS 'Dist Staging to Dev'"/>

回答1:


If you use MSBuild 4, you could use Property function

<Import Project="A.proj" 
        Condition="$(BuildDefinition.Contains('Dist Staging to Dev'))"/>

(More info on Property function)




回答2:


MSBuild4: As Julien said, in MSBUILD 4 is possible to user Property Function.

MSBuild 3.x: In previous versions is possible if you use Tigris MsBuild Tasks

You can use task RegexMatch and use a regular expression




回答3:


MsBuild Conditions reference doesn't have anything about a possibility of a "contains" function. Looks like your first version is the only option.



来源:https://stackoverflow.com/questions/3289538/is-there-any-msbuild-task-to-check-if-a-string-contains-another-string-similar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!