我正在研究构建过程的自定义,并且遇到了一个有趣的行为。当使用字符串Property函数并更改一些字符串时,构建开始中断。属性函数的奇怪行为
例如,我试图做这件事:
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn.Replace(";MyTarget", ""))</BuildDependsOn>
</PropertyGroup>
的MyTarget是,我想从BuildDependsOn属性中删除我的自定义的目标。当我试图做到这一点,字符串似乎被正确地删除,但我得到的错误,目标不存在(这发生在Visual Studio 2010和通过命令行MSBuild)。
错误是以下几点:
The target "EntityDeploy;
BeforeBuild;
CoreBuild;
AfterBuild" does not exist in the project.
我想,一旦我修改此属性,MSBuild的停止解析其价值,并试图寻找一个目标(包括白色空格,回车和新换行):
"EntityDeploy;
BeforeBuild;
CoreBuild;
AfterBuild"
并抛出一个错误,指出这样的目标不存在。
我也曾尝试进行一些更琐碎,了解更多关于这个问题,我试图执行此:
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn.Trim())</BuildDependsOn>
</PropertyGroup>
错误再次出现也与Trim()
功能。 有什么想法?
编辑:我试图调试,并找出问题,我也碰到过这样的: 当Trim()
方法的执行之前检查属性BuildDependsOn
,它的价值是这样的:
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()
方法,该属性值是这样的:
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)正在打破构建?我怎样才能解决这个问题?
也许这些链接可能会帮助你:http://stackoverflow.com/questions/5103026/in-msbuild-can-i-use-the-string-replace-function-on-a-metadata-item和这一个太http://msdn.microsoft.com/en-us/library/ms171458(v=vs.100).aspx – lnu 2012-04-05 06:59:58
我知道这个OOB,但你不能做惯用的MSBuild的东西,并定义一个属性组与目标和一个出来,然后使用配置来选择哪一个被启用? – 2012-04-05 09:49:06
@RitchMelton在正常情况下,我可以...事实上,我已经发布了我有的问题的简化版本。问题是,当我包含第三方.Targets文件时,第三方目标会自动添加到BuildDependsOn属性中。我想从这个属性中移除它(这样它就不会在构建项目时运行),并在另一个条件中决定是否应该执行目标。 – 2012-04-05 11:45:07