这是一个简单的测试项目
<?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>
答案 0 :(得分:0)
您应该使用项目组对参数和值的集合进行逻辑分组,并使用MSBUILD转换来获取您希望看到的输出。
<Target Name="SemiColon">
<ItemGroup>
<Parm Include="Parm1">
<Value>Val1</Value>
</Parm>
<Parm Include="Parm2">
<Value>Val2</Value>
</Parm>
<Parm Include="Parm3">
<Value>Val3</Value>
</Parm>
<Parm Include="Parm4">
<Value>Val4</Value>
</Parm>
<ParamLine Include="%(Parm.identity )=%(Parm.Value)" />
</ItemGroup>
<Message Importance="High"
Text="Parameter Name and Value: @(ParamLine, ';')" />
<Message Importance="High"
Text="Just values: @(Parm -> MetaData('Value'))" />
</Target>
ParamLine项使用MsBuild变换来格式化Param = Val格式的输出,而第二个只显示以分号分隔的值。
Parameter Name and Value: Parm1=Val1;Parm2=Val2;Parm3=Val3;Parm4=Val4
Just values: Val1;Val2;Val3;Val4