繁体   English   中英

Visual Studio 2010 Post-Build Step中的Powershell脚本

[英]Powershell script in Visual Studio 2010 Post-Build Step

我有一个PowerShell脚本,可以从powershell shell和cmd窗口中运行,现在我尝试从Visual Studio中的后期构建步骤启动它。

在尝试将其送到午餐并成功运行的几种不同变体之后,我目前对VS2010中“后构建事件”的“命令行”属性进行了以下配置。

这只是Post-Build配置中的一行,但为了便于阅读,我将文本包装在这里:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive
-File "$(SolutionDir)testScript.ps1"
-ConfigurationFile "$(SolutionDir)configuration.txt"
-SolutionDir "$(SolutionDir)"
-Platform "$(Platform)"
-Configuration "$(Configuration)"

powershell脚本需要4个必需参数:ConfigurationFile,SolutionDir,Platform和Configuration。 如您所见,我提供上述每个参数,并将它们用双引号括起来以防止值中的空格。

在VS2010中,SolutionDir宏扩展为具有空格的路径,Platform扩展为“Release”,Configuration扩展为“Win32”。

执行后构建步骤时,这是我得到的错误:

testScript.ps1 : Cannot process command because of one or more missing
mandatory parameters: Platform Configuration.
    + CategoryInfo          : InvalidArgument: (:) [testScript.ps1], 
    ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingMandatoryParameter,testScript.ps1

......任何想法,我可能会失踪? 它显然能够在$(SolutionDir)中找到该脚本,但我无法判断它是否正在接收任何命令行参数。 $(SolutionDir)中的尾随'\\'字符是否会挂起来?

变量$(SolutionDir) ,因为它是一个以反斜杠'\\'结尾的目录。 因此,当扩展变量时, -SolutionDir "$(SolutionDir)"的参数如下所示:

-SolutionDir "c:\Your Solution Dir\"

当解析它时,最终的斜杠有效地逃避了结束引用,并且shell解析器没有看到参数的结束,因此-SolutionDir的参数将其余的参数“吸入”到SolutionDir参数中。 您可以通过添加尾部斜杠来使用另一个反斜杠转义最终反斜杠来解决此问题:

-SolutionDir“$(SolutionDir)\\”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM