Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the full path to MSBuild.exe #74

Closed
uli-weltersbach opened this issue May 31, 2017 · 5 comments
Closed

Getting the full path to MSBuild.exe #74

uli-weltersbach opened this issue May 31, 2017 · 5 comments
Labels
duplicate question Question or support request.

Comments

@uli-weltersbach
Copy link

Hi

I feel like I'm missing some obvious way to determine the full path to MSBuild.exe.
To illustrate, here's where we're at currently:

  1. Run vswhere.exe -latest -requires Microsoft.Component.MSBuild -property installationFolder.

  2. The return value "C:\Path\To\VisualStudio\Root" seems useless, because we have to make an additional assumption reg. the location of MSBuild.exe inside that folder.
    We could append "\MSBuild\15.0\MSBuild\bin\MSBuild.exe", but that seems to defeat the purpose of not making assumptions/including hard coded paths in our build scripts.

  3. Run vswhere.exe -latest -requires Microsoft.Component.MSBuild -property installationVersion.

  4. The return value "15.0.26430.6" seems useless, because the actual path is "C:\Path\To\My\VisualStudio\Root\15.0\" which means we'd again need to do additional handling, e.g. using either a 2 or 3 digit substring based on whether the major revision is less than/greater than 10.

@uli-weltersbach
Copy link
Author

uli-weltersbach commented May 31, 2017

On a more general note: Is this tool in any way intended to be runnable on a build server which ONLY has MS Build Tools installed, i.e. no version of Visual Studio?

EDIT: Having read through #41 I guess I'll look somewhere else :(

@3F
Copy link

3F commented May 31, 2017

you can try something like this if you need only full path to msbuild from VS2017+ through vswhere:

...
for /f "usebackq tokens=1* delims=: " %%a in (`!vswbin! -latest -requires Microsoft.Component.MSBuild`) do (
    if /i "%%a"=="installationPath" set vspath=%%b
    if /i "%%a"=="installationVersion" set vsver=%%b
)
...
for /f "tokens=1,2 delims=." %%a in ("!vsver!") do (
    set vsver=%%a.%%b
)
set msbuildPath=!vspath!\MSBuild\!vsver!\Bin

this part from hMSBuild helper that you already noticed above (we're using this for simple access to msbuild tools -_- as a common tool for all VS & .NET versions)

just to be clear, the latest version also already supports a local vswhere tool (#41 *now I updated info there) and via key -vswhere-version can control this behaviour:

 -vswhere-version {num} - Specific version of vswhere. Where {num}:
                          * Versions: 1.0.50 ...
                          * Keywords:
                            `latest` to get latest available version;
                            `local`  to use only local versions:
                                     (.bat;.exe /or from +15.2.26418.1 VS-build);

@uli-weltersbach
Copy link
Author

Thanks for the reply, I've already downloaded hMSBuild.bat and am working on getting it into our build system :)

@heaths
Copy link
Member

heaths commented May 31, 2017

If you look at the wiki there are plenty of examples, and issue #61 describes - as do the docs and command line usage text - that vswhere searches for VS by default but can easily support Build Tools as well.

@heaths heaths closed this as completed May 31, 2017
@heaths heaths added duplicate question Question or support request. labels May 31, 2017
@heaths
Copy link
Member

heaths commented May 31, 2017

Also, as of Visual Studio 2017 version 15.2 vswhere will always be available in %ProgramFiles(x86)%\Microsoft Visual Studio\Installer if VS, Build Tools, Remote Tools, or other 2017 family of products or newer is installed.

But that still doesn't change the fact that support for -legacy is, as documented, limited. That was a feature I added solely to find the roots of then-supported Visual Studio installations that did not use the query API. Older versions of MSBuild were not limited to being installed by VS and are locatable by other means. You will need to script your environment appropriately to handle legacy MSBuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate question Question or support request.
Projects
None yet
Development

No branches or pull requests

3 participants