I have a powershell script that works wonderfully from the powershell shell and from a cmd window, and now I am trying to launch it from a post-build step in Visual Studio.
After several different variations of trying to get this to lunch and run successfully, I currently have the following configuration for the "Command Line" property of the "Post-Build Event" in VS2010.
This is all on one line in the Post-Build configuration, but I've wrapped the text here just for readability:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive
-File "$(SolutionDir)testScript.ps1"
-ConfigurationFile "$(SolutionDir)configuration.txt"
-SolutionDir "$(SolutionDir)"
-Platform "$(Platform)"
-Configuration "$(Configuration)"
The powershell script expects 4 mandatory parameters: ConfigurationFile, SolutionDir, Platform, and Configuration. As you can see, I am providing each of those parameters above, and am enclosing them in double quotes to protect against spaces in the values.
In VS2010, the SolutionDir macro expands to a path that has spaces, Platform expands to "Release", and Configuration expands to "Win32".
When the post-build step executes, this is the error I get:
testScript.ps1 : Cannot process command because of one or more missing
mandatory parameters: Platform Configuration.
+ CategoryInfo : InvalidArgument: (:) [testScript.ps1],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingMandatoryParameter,testScript.ps1
...any ideas what I could be missing? It is apparently able to find the script in $(SolutionDir), but I can't tell whether it's picking up any of the command line arguments. Could the trailing '\' character in $(SolutionDir) be hanging this up?
The variable $(SolutionDir)
, since it is a directory ends in a backslash '\'. So, when the variable is expanded, the argument for -SolutionDir "$(SolutionDir)"
looks like this:
-SolutionDir "c:\Your Solution Dir\"
when this is parsed the final slash effectively escapes the closing quote and the shell parser does not see the end of the argument, so the parameter to -SolutionDir
"sucks in" the rest of the arguments into the SolutionDir argument. You can fix this by escaping the final backslash with another one by adding a trailing slash:
-SolutionDir "$(SolutionDir)\"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With