MsBuild条件评估属性包含

MsBuild条件评估属性包含

本文介绍了MsBuild条件评估属性包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试创建在文件类型为-Filename.CSS.ASPX的目标中使用的项目组

Attempting to create an itemgroup for use in a target where the file types are - Filename.CSS.ASPX

<Target Name="Test" AfterTargets="Build">
    <Message Text="Project $(ProjectName) Test PostBuild" Importance="high" />
    <Message Text="%(Content.FullPath)" Condition="%(Extension) == '.aspx' AND %(Filename.Contains(css))" Importance="high" />
</Target>

编译时;

Error   1   Expected "%(Filename.Contains(css))" to evaluate to a boolean instead of "%(Filename.Contains(css))", in condition "%(Extension) == '.aspx' AND %   (Filename.Contains(css))".  C:\Projects\TestProj\TestProj\TestProj.csproj   58  38  TestProj

关于扩展属性以进行评估的任何建议吗?

Any advice on expanding properties for evaluation?

推荐答案

据我所知,您只能将字符串函数(如代码中的Contains)用于属性,而不能用于项目元数据.但是您尝试为%(Filename)调用Contains,这是Content项的元数据.

As far as I know, you can use string functions (like Contains in your code) only for properties, not for item metadata. But you tried to invoke Contains for %(Filename) and this is a metadata of Content item.

要获取更多详细信息,请参见链接到MSDN .最后一段严格说:

To get more details see link to MSDN. The last paragraph strictly says:

但是,可以使用Regex类的静态方法.我相信下面的代码就是您想要的:

However, you can use static methods of Regex class. I believe the following code is what you wanted:

<Target Name="Test" AfterTargets="Build">
    <Message Text="Project $(ProjectName) Test PostBuild" Importance="high" />
    <Message Text="%(Content.FullPath)" Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch('%(FullPath)', '.+\.css\.aspx')) " Importance="high" />
</Target>

如果没有,则可以根据需要修改正则表达式.

If not, you can modify the regular expression in any way you need.

这篇关于MsBuild条件评估属性包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:46