【发布时间】:2015-11-23 16:33:19
【问题描述】:
当在构建机器上启动构建时,我正在尝试运行一个简单的 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=""$(PowerShellExe)" "$(MSBuildProjectDirectory)\Build.ps1" -slnPath "$(MSBuildProjectDirectory)\" -tfExeLocation "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe" "/>
这是我正在使用的 Powershell 脚本
Param(
[string]$slnPath,
[string]$tfExeLocation
)
Push-Location "$slnPath"
write-output "Made it past push location"
& '"$tfExeLocation'" checkout *.csproj Packages.Config* /recursive
Pop-Location
非常感谢任何帮助。我很确定这很简单,因为我最近才开始使用 msbuild 组件和 Powershell。
【问题讨论】:
-
@PetSerAl 这不起作用。它给了我一个错误,指出“D:\Builds\23\WS\Main-SWS\Sources\Student\Main\StudentSoln\Build.ps1\”不是 cmdlet、函数、脚本文件或可操作的名称程序。
-
删除额外的
\字符:<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 没有注意到多余的斜线,所以谢谢。使用该更新再次尝试并使其正常工作。您介意将其发布为答案,以便我将其标记为答案吗?
标签: powershell visual-studio-2012 msbuild