&安培;在XML中不会被&取代

时间:2014-11-05 18:29:47

标签: xml powershell msbuild escaping

我目前正在调整我的msbuild文件以进行持续集成。更具体地说,我尝试在Microsoft official help的指导下调用powershell在msbuild文件中的远程服务器上执行任务。一切都很棒,除了"& amp;"在msbuild文件中不会被"&"取代。例如,

<Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted 
                 -command &quot;&amp; invoke-command 
                          -Computername &apos;RemoteServer&apos;
                          -scriptblock {...}
                          &quot;"/>  

当msbuild脚本包含上述执行时,该命令将转换为

powershell.exe -NonInteractive -executionpolicy Unrestricted 
             -command "&amp; invoke-command 
                      -Computername 'RemoteServer'
                      -scriptblock {...}
                      " 

如您所见,&#34;&amp; quot;&#34;和&#34;&amp;&#34;成功翻译,而&#34;&amp; amp;&#34;不是。

非常感谢任何线索!

1 个答案:

答案 0 :(得分:0)

即使执行msbuild脚本会抱怨命令和显示&#34;&amp; amp;&#34;在消息中。但它不是问题的根源。

root是msbuild脚本不喜欢使用单个powershell命令来扩展多行。

<Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; invoke-command -Computername &apos;RemoteServer&apos; -scriptblock {...}  &quot;"/>  

一旦我像上面那样改变它。它按预期工作。