4

I have a command in my post-build event command line in Visual Studio 2010

Powershell -command .'$(SolutionDir)Powershell\MoveFiles.ps1'

And when the event runs, I get an error that the command "exited with code 1."

However when I run the same command on the command line (see below), with an actual directory instead of the VS2010 macro, it works perfectly.

Powershell -command .'C:\TFS\MyProject\Main\Source\Powershell\MoveFiles.ps1'

So it seems that the problem lies with how VS2010 is executing the command.

What could be causing this problem?

[UPDATE]

I have also tried changing the post-build event to:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell -command .'C:\TFS\MyProject\Main\Source\Powershell\MoveFiles.ps1' and I get the same result as described above. It works when run from the command line but not from VS 2010.

2
  • The same result: as in working perfectly, or giving you a error? Commented Dec 19, 2011 at 23:09
  • In Visual Studio build and get the error. Then select "View" from the top menu and select "Output". The output window will come up. Examine the content in the window and if the reason is still unclear, please post the output here. Cheers. Commented Dec 19, 2011 at 23:25

2 Answers 2

4

Two things:

  1. Use the -file parameter instead of the -command parameter.
  2. Use double quotes.

powershell.exe -file "$(SolutionDir)Powershell\MoveFiles.ps1"

Sign up to request clarification or add additional context in comments.

Comments

3

If you are running on a 64-bit OS, you will need to specify the full path to the 64-bit version of powershell since Visual Studio is a 32-bit app.

There is an answer in this question that has a workaround for the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.