这是简单的测试项目
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="configure">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<PropertyGroup>
<param>var1=val1,var2=val2</param>
</PropertyGroup>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Target Name="configure" DependsOnTargets="" Outputs="">
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Properties="component=c1;$(param.Replace(',',';'))"
Targets="process"/>
</Target>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Target Name="process">
<Message Text="[$(component)][$(var1)][$(var2)]"/>
</Target>
</Project>
我希望看到
[c1][val1][val2]
但不幸的是,msbuild 不会从我的字符串和输出中解析其他属性
[c1][val1;var2=val2][]
任何想法如何帮助 msbuild?谢谢
解决方案:使用 [MSBuild]::Unescape
<PropertyGroup>
<p>var1=val1,var2=val2</p>
<param>$([MSBuild]::Unescape($(p.Replace(',',';'))))</param>
</PropertyGroup>