Powershell Command post-build VS2010

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

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

And when the event is fired, 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 the actual directory instead of the VS2010 macro, it works fine.

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

So it seems that the problem is how the VS2010 executes the command.

What could be causing this problem?

[UPDATE]

I also tried changing the post-build event:

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

+4
source share
2 answers

Two things:

  • Use the -file instead of the -command .
  • Use double quotes.

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

+4
source

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

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

+3
source

Source: https://habr.com/ru/post/1387113/


All Articles