1

Not sure how to do this... I work mostly on OSX and linux systems, so when I install an app or use for example G++ or xcodebuild, I just call it from terminal.

On Windows, I did install msbuild with VS2015, but if I am in powershell or regular command prompt, typing msbuild result in an error. I have to specify the whole path to make it work.

What is the equivalent in Windows world, of setting console so when I type msbuild, it gets the correct path?

2 Answers2

2

You can set your path like so in:

PowerShell

$Env:Path = "<Path_to_msbuild>;${Env:Path}"

Batch/Cmd

set "PATH=<Path_to_msbuild>;%PATH%"

Note: The <path_to_msbuild> is the folder where msbuild.exe exists, and NOT the direct path to the executable itself

How it works

This will add the msbuild binary to your path, so you can invoke it from anywhere!

To verify which location msbuild is running from you can simply run (in both languages!):

where.exe msbuild
AP.
  • 8,082
  • 2
  • 24
  • 33
  • `where.exe msbuild` won't help here, otherwise there wouldn't be any need to add the MSBuild directory to the path, would there? – Ansgar Wiechers Apr 05 '17 at 22:19
  • 1
    `Where.exe` here is used as a ***verification*** step to check that msbuild was added correctly to the `PATH` variable – AP. Apr 05 '17 at 22:21
  • Fair enough. You can actually discover the path with `where.exe`, though, if you know at least the rough location: `where.exe /r "C:\Program Files" msbuild` – Ansgar Wiechers Apr 05 '17 at 22:23
  • weird I can't call msbuild using full path in PowerShell – Toolkit Nov 22 '20 at 10:18
  • I have a feeling you've added `msbuild.exe` in your path. That's not how PATHs work. https://docs.alfresco.com/4.2/tasks/fot-addpath.html You need to add the ``. I made my answer more explicit! – AP. Nov 23 '20 at 21:08
1

If you create just a link to msbuild you still won't be able to call for example the compiler from the command line. Which is why VS provides a convenient (pretty much canonical) way to do this by supplying a batch file which sets up the PATH and all the other build-related environment variables.

Example if you are on cmd.exe:

> "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"

> msbuild
Microsoft (R) Build Engine version 14.0.25420.1
...
> cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x86
...

You can invoke this from the Start menu as well: hit start, type pro vs to look for matches, select Developer Command Prompt for VS2015.

For PowerShell (which I'd recommend spending time on instead of cmd) you'll need an extra function like presented here: https://stackoverflow.com/a/21652729/128384

Community
  • 1
  • 1
stijn
  • 34,664
  • 13
  • 111
  • 163
  • Thanks a lot! Do I have to call the VSDevCmd every time? The machine usually stay up but I may need to reboot it at times. –  Apr 08 '17 at 04:33
  • You need to call it everytime you launch a process in which you need it, i.e. it doesn't set global system-wide environment variables for the OS (that would be a disaster with regards to building with different versions of VS). So every time you start PS or cmd and need the build tools, call it once. Nice thing about PS: add a function to your profile and be done with it. – stijn Apr 08 '17 at 11:07