Powershell script in Visual Studio 2010 Post-Build Step


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:

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:

…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:

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)\”


Powershell script in Visual Studio 2010 Post-Build Step by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply