属性函数的奇怪行为 [英] strange behavior of Property functions

查看:62
本文介绍了属性函数的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在定制我的构建过程,我遇到了一个有趣的行为.使用字符串属性函数并更改某些字符串时,构建开始中断.

I am working on a customization of my build proces and I've come across one interesting behavior. When using string Property functions and altering some strings, the build starts to break.

例如,我正在尝试做这件事:

For example, I'm trying to do this thing:

<PropertyGroup>
    <BuildDependsOn>$(BuildDependsOn.Replace(";MyTarget", ""))</BuildDependsOn>
</PropertyGroup>

MyTarget 是我想从 BuildDependsOn 属性中删除的自定义目标.当我尝试这样做时,该字符串似乎已被正确删除,但我收到目标不存在的错误(这在 Visual Studio 2010 中和通过命令行 MSBuild 都会发生).

The MyTarget is my custom target that I want to remove from the BuildDependsOn property. As I try to do this, the string seems to be removed correctly, but I am getting error that the target does not exist (this happens both in Visual Studio 2010 and via command-line MSBuild).

错误如下:

The target "EntityDeploy;

            BeforeBuild;
            CoreBuild;
            AfterBuild" does not exist in the project.

我认为一旦我修改了这个属性,MSBuild 就会停止解析它的值并试图寻找一个名为:

I think that once I modify this property, the MSBuild stops to parse its value and is trying to look for one target (including white-spaces, carriage returns and new line feeds) called:

"EntityDeploy;

        BeforeBuild;
        CoreBuild;
        AfterBuild"

并抛出这样的目标不存在的错误.

and throws an error that such target does not exist.

我还尝试执行一些更琐碎的操作以了解有关此问题的更多信息,并且我已尝试执行此操作:

I have also tried to perform something more trivial to find out more about this problem and I've tried to perform this:

<PropertyGroup>
    <BuildDependsOn>$(BuildDependsOn.Trim())</BuildDependsOn>
</PropertyGroup>

Trim() 函数也再次出现该错误.有什么想法吗?

The error appeared again also with the Trim() function. Any idea?

我试图调试并找出问题,但我遇到了这个:在执行Trim()方法之前检查属性BuildDependsOn时,它的值是这样的:

I have tried to debug and find out the problem, and I have come across this: When checking property BuildDependsOn before the execution of the Trim() method, its value is like this:

Value   "BuildDependsOn"="\r\n      EntityDeploy;\r\n      \r\n            BeforeBuild;\r\n            CoreBuild;\r\n            AfterBuild\r\n        \r\n    "
EvaluatedValue  "\r\n      EntityDeploy;\r\n      \r\n            BeforeBuild;\r\n            CoreBuild;\r\n            AfterBuild\r\n        \r\n    " string
escapedValue    "\r\n      EntityDeploy;\r\n      \r\n            BeforeBuild;\r\n            CoreBuild;\r\n            AfterBuild\r\n        \r\n    " string

Trim()方法之后,属性值是这样的:

After Trim() method, the property values are like this:

Value   "BuildDependsOn"="EntityDeploy%3b\r\n      \r\n            BeforeBuild%3b\r\n            CoreBuild%3b\r\n            AfterBuild"
EvaluatedValue  "EntityDeploy;\r\n      \r\n            BeforeBuild;\r\n            CoreBuild;\r\n            AfterBuild"   string
escapedValue    "EntityDeploy%3b\r\n      \r\n            BeforeBuild%3b\r\n            CoreBuild%3b\r\n            AfterBuild" string

可能是分号 (; <=> %3b) 破坏了构建?我该如何解决这个问题?

Might it be that semicolons (; <=> %3b) are breaking the build? How can i fix this?

推荐答案

我尝试了您所做的(向 BuildDependsOn 添加修剪)并且它正在工作.

I tried what you did(adding a trim to BuildDependsOn) and it's working.

 <BuildDependsOn>
  ConfigBeforeBuild;
  $(BuildDependsOn.Trim());
  ConfigAfterBuild
</BuildDependsOn>

您是否为 msbuild 启用了调试?如果不是一切都解释了 这里.

Did you enabled debugging for msbuild? if not everything is explained here.

好的,这是解决方案(我的也没有用,我的测试不正确):

Ok, here's the solution(mine was not working either, my test was not correct):

<BuildDependsOn>
  $([MSBuild]::Unescape($(BuildDependsOn.Replace(";MyTarget", ""))))
</BuildDependsOn>   

您必须取消转义字符串才能删除 %3b.

You have to unescape your string in order to remove the %3b.

这篇关于属性函数的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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