Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使msbuild和powershell更好地解析包含空格的路径_Powershell_Visual Studio 2012_Msbuild - Fatal编程技术网

无法使msbuild和powershell更好地解析包含空格的路径

无法使msbuild和powershell更好地解析包含空格的路径,powershell,visual-studio-2012,msbuild,Powershell,Visual Studio 2012,Msbuild,我正在尝试在生成计算机上启动生成时运行一个简单的powershell脚本。从我可以看出,问题在于我发送的tfExeLocation的路径,因为它包含空格。我尝试了几种不同的方法来转义路径,以便msbuild和powershell都满意它,但我遗漏了一些东西 我得到的当前错误是: Task "Exec" (TaskId:3) Task Parameter:Command="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

我正在尝试在生成计算机上启动生成时运行一个简单的powershell脚本。从我可以看出,问题在于我发送的tfExeLocation的路径,因为它包含空格。我尝试了几种不同的方法来转义路径,以便msbuild和powershell都满意它,但我遗漏了一些东西

我得到的当前错误是:

Task "Exec" (TaskId:3)
  Task Parameter:Command="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
      "D:\Builds\23\WS\Main-SWS\Sources\Student\Main\StudentSoln\Build.ps1"
      -slnPath "D:\Builds\23\WS\Main-SWS\Sources\Student\Main\StudentSoln\"
      -tfExeLocation "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe"  (TaskId:3)
  "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
  "D:\Builds\23\WS\Main-SWS\Sources\Student\Main\StudentSoln\Build.ps1"
  -slnPath "D:\Builds\23\WS\Main-SWS\Sources\Student\Main\StudentSoln\"
  -tfExeLocation "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe"  (TaskId:3)
  The string is missing the terminator: ". (TaskId:3)
      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx  (TaskId:3)
     ception (TaskId:3)
      + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString (TaskId:3)
    (TaskId:3)
Done executing task "Exec". (TaskId:3)
这是来自项目文件中目标的调用

<PropertyGroup>
  <PowerShellExe Condition="'$(PowerShellExe)'=='' ">$(WINDIR)\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
</PropertyGroup>
<Exec Command="&quot;$(PowerShellExe)&quot; &quot;$(MSBuildProjectDirectory)\Build.ps1&quot; -slnPath &quot;$(MSBuildProjectDirectory)\&quot; -tfExeLocation &quot;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe&quot; "/>

非常感谢您的帮助。我很确定这很简单,因为我最近才开始使用msbuild组件和Powershell

命令中的引号有问题。简单的解决方案是在PowerShell命令中使用单引号,并将所有命令放在双引号中

"$(PowerShellExe)" "& '$(MSBuildProjectDirectory)\Build.ps1' -slnPath '$(MSBuildProjectDirectory)\' -tfExeLocation 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe'"
在正确的XML转义之后,将变成:

<Exec Command="&quot;$(PowerShellExe)&quot; &quot;&amp; '$(MSBuildProjectDirectory)\Build.ps1' -slnPath '$(MSBuildProjectDirectory)\' -tfExeLocation 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe'&quot;" />


@PetSerAl不起作用。它给了我一个错误,指出“D:\Builds\23\WS\Main SWS\Sources\Student\Main\StudentSoln\Build.ps1”不被识别为cmdlet、函数、脚本文件或可操作程序的名称。删除额外的
\
字符:
@PetSerAl没有注意到额外的斜杠,因此对此表示感谢。用那个更新再试一次,结果成功了。你介意把这个贴出来作为答案吗?这样我就可以把它标出来了?
<Exec Command="&quot;$(PowerShellExe)&quot; &quot;&amp; '$(MSBuildProjectDirectory)\Build.ps1' -slnPath '$(MSBuildProjectDirectory)\' -tfExeLocation 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe'&quot;" />