【问题标题】:& in XML does not get replaced by &XML 中的 & 不会被 & 取代
【发布时间】:2015-01-02 01:45:39
【问题描述】:

我目前正在调整我的 msbuild 文件以进行持续集成。更具体地说,在Microsoft official help 的指导下,我尝试在msbuild 文件中调用powershell 在远程服务器上执行任务。一切都很棒,除了“&”在 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 {...}
                      " 

如您所见,“”和“’”已成功翻译,而“&”不是。

非常感谢任何线索!

【问题讨论】:

    标签: xml powershell msbuild escaping


    【解决方案1】:

    即使执行 msbuild 脚本会报错命令并显示“&”在消息中。但这不是问题的根源。

    root是msbuild脚本不喜欢单个powershell命令分散多行。

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

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

    【讨论】:

      猜你喜欢
      • 2018-12-26
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多