0

I am trying to run a simple command from powershell, but as always with powershell nothing works.

I cannot get this to work regardless how many different quotes I try.

PS> Measure-Command { C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe test.sln /Build } 

1 Answer 1

2

A command lines such as

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe test.sln /Build

wouldn't work in any shell, because, due to the lack of quoting around the executable path, necessitated by that path containing spaces, would result in C:\Program being interpreted as the executable path. In other words: quoting such a path is a must.

What is PowerShell-specific is the need to use &, the call operator whenever an executable path is quoted and/or contains variable references / expressions (which is a purely syntactical requirement explained in this answer; if you don't want to think about when & is required, you may always use it).

Additionally, as you've discovered yourself, for synchronous, console-based operation, you must call devenv.com, not devenv.exe.[1]

Therefore:

Measure-Command { 
 & 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.com' test.sln /Build 
} 

Note that since the path a literal one (no variable references / expressions), use of single-quoting ('...') is preferable; for more information about string literals in PowerShell, see the bottom section of this answer.


[1] In case you need to invoke a GUI-subsystem application synchronously (wait for it to exit) - which run asynchronously by default - use Start-Process -Wait.

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

3 Comments

This command "Measure-Command { & 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe' test.sln /Build }" has the effect that devenv is started in the background, so Measure-Command measures how long time it takes to start it. Not how long it takes to build the solution.
Oh man. Turns out I have to use devenv.com. Then it works.
Good to know, @GenericName - I've updated the answer accordingly.

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.