How do I update the PATH variable to the current location of MSBUILD15

BobbyA's Avatar

BobbyA

12 Sep, 2018 10:50 PM

In another discussion about the location of MSBuild15, If found an example Powershell line that could locate it:
https://help.appveyor.com/discussions/questions/3723-could-build-tools-for-visual-studio-2017-be-installed-to-the-vs-2017-image

    $msbuildPath = $(cmd /c where msbuild)

I want to add that path to the PATH environment variable. Isolating just the path would look like this in powershell:

    $msbuildPath = $(cmd /c where msbuild).Substring(0,$var.IndexOf("MSBuild.exe"))

But I'm not sure what the best way to get that dynamically discovered path to be added to the PATH environment variable. Under install: there's a set command I can use to set the PATH environment variable, but that's outside the context of any powershell script I'd run before that.

What's the right way to do this?

Thanks!

  1. Support Staff 1 Posted by Ilya Finkelshte... on 12 Sep, 2018 11:41 PM

    Ilya Finkelshteyn's Avatar

    Why would you do this? I did not test your command, but if where msbuild works, this means that exactly the same path already in the PATH environment variable. Otherwise where msbuild would not work...

    What is bigger problem you are solving?

  2. 2 Posted by BobbyA on 13 Sep, 2018 01:48 PM

    BobbyA's Avatar

    Ha, wonderful You're right. I've been tasked with updating an existing repo to verify it's compatible with Visual Studio 2017, and my appveyor builds started breaking when I updated:

        os: Visual Studio 2015

    to

        os: Visual Studio 2017

    because it was using MSBuild 14.0. The appveyor.yml file had this script happening during the install phase:

        install:
          - set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%

    So I was trying to update that line, but it didn't occur to me to check if we really needed that line (or that Feodor's line from the other question wouldn't work if MSBuild's directoery wasn't already in the path)

    Thanks!

  3. Support Staff 3 Posted by Ilya Finkelshte... on 13 Sep, 2018 01:50 PM

    Ilya Finkelshteyn's Avatar

    Good, thanks for the update :)

  4. Ilya Finkelshteyn closed this discussion on 13 Sep, 2018 01:50 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac