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
.