我有一个 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) 中的尾随 '\' 字符会挂起吗?