Skip to content

Searching of MSBuild tools: vswhere + VS as an initial tool by default #41

Closed

Description

@3F

How about to provide this (or similar) tool by default with VS as front-controller (into one known unified place) for simple requests about simple informations like searching of available msbuild tools and other informations about all installed VS instances ?

It's important for any small tools like this, that contains all logic via single batch file etc.
I mean just look the gnt.bat (full logic for work with nuget packages: creating new, installing, etc. via msbuild) and tell me, how we should now ? +vswhere.exe ?

For any searching of msbuild tools it looked like this msbuild-helper before (to build in any places like CI build-servers, any custom user's env etc. - easy and works well)

this:

for /f "usebackq tokens=1* delims=: " %%i in (`vswhere -latest -requires Microsoft.Component.MSBuild`) do (
  if /i "%%i"=="installationPath" set InstallDir=%%j
)
...

is much more useful when your vswhere (or something else) will be provided initially as a simple console tool and located in already known place (to aggregate any requests as front-controller as I said above).

This is possible by MS ? or how it should be now for something like above ?

Update 1

Final solutions to find msbuild.exe from VS2017:

Via batch scripts ( no powershell, no dotnet cli )

For online machines, now appeared this - https://github.com/3F/hMSBuild

A single compiled batch file ~19 Kb that can be embedded inside any scripts or other batch files:

Usage is same as it would be same for msbuild.

Usage: hMSBuild [args to hMSBuild] [args to msbuild.exe or GetNuTool core]
------

Arguments:
----------
 -no-vs        - Disable searching from Visual Studio.
 -no-netfx     - Disable searching from .NET Framework.
 -no-vswhere   - Do not search via vswhere.

 -vsw-version {arg}  - Specific version of vswhere. Where {arg}:
     * 2.6.7 ...
     * Keywords:
       `latest` - To get latest remote version;
       `local`  - To use only local versions;
                  (.bat;.exe /or from +15.2.26418.1 VS-build)
...

Solution by Microsoft

here:

After further discussion internally, we're going to add vswhere.exe to a known location (such as %CommonProgramFiles%) in an upcoming servicing release, which will address the original issue as proposed by Denis Kuzmin (@3F) at the top of the thread. This will give you the flexibility to use ...

Update 2

here by Heath Stewart (@heaths):

vswhere is now available as part of the install starting today with Visual Studio 15.2 preview 2:

Update 3

Just removed direct links to hMSBuild 1.x ( 2017, which are still actively referenced ). Please use latest versions:

🧱 Compiled text-based embeddable pure batch-scripts for searching of available MSBuild tools.

Activity

  1. heaths commented on Mar 14, 2017

    @heaths
    Member

    We are considering this, but even if we did in a subsequent update, VS2017 RTW already shipped. vswhere was meant to be redistributed as needed, so I the meantime and for VS2017 RTW support you could consider adding the file to the repo.

  2. 3F commented on Mar 14, 2017

    @3F
    Author

    VS2017 RTW already shipped

    Yes, I noticed -_- ... and I don't know how to easily solve this problem instead of adding vswhere for a lot of public repos.

    Moreover, as you can see this can be a simple small script-tool for end-users. So I don't know what to do at all for this cases (well, I know but...), because now it requires ... omg.

    As I see, gnt.bat tool above should correctly work via tool from .NET Framework, thus nuget-packages are still not problem and we can distribute vswhere automatically (like for other my X tool for additional complex build-scripting that wrapped by single bat file and distributed via nuget server), however: the nuget package will not useful for offline machines :(, so the easy way, yes, to distribute 'as is' together with repo. That's of course amazing for simply finding path to the msbuild tools <_<

    Need to think -_-

    We are considering this

    Good ! I hope to see something from next patch-releases at least.

    Thanks,

  3. KindDragon commented on Mar 17, 2017

    @KindDragon
    Contributor

    or how it should be now for something like above ?

    You can try to install it from Chocolatey, It will be automatically added to PATH

  4. 3F commented on Mar 17, 2017

    @3F
    Author

    It will be automatically added to PATH

    the problem not for path to vswhere because we can still use gnt like:

    :: to get the vswhere & vsSBE packages
    gnt /p:ngpackages="vswhere;vsSBE.CI.MSBuild"
    
    :: we're ready for vswhere
    %vswhere% -latest -requires Microsoft.Component.MSBuild
    ...
    
    :: build Conari project via powerful vsSBE scripts & msbuild tools from found path by vswhere
    %msbuild% -notamd64 "Conari.sln" /l:"CI.MSBuild.dll" ... || goto err
    ...
    etc.

    but thanks, it's first time when I hear about chocolatey :)

  5. grafikrobot commented on Mar 28, 2017

    @grafikrobot

    The Boost C++ Libraries project lobbied for this to be included before the release went out. But those requests failed. Most likely the VS release manager didn't consider this a high-priority issue. But now we have a situation where many different projects like Boost, Cmake, etc will end up including a patchwork of incompatible detection methods in their repos.

    For Boost including the executable of this utility might be an option.. If it where not for the license. As, if you can believe, the Boost license is less restrictive than the MIT license in use for vswhere. My suggestion would be to relicense vswhere to the "Public Domain" or the "Boost License", or some other license that doesn't require license terms for binary inclusion.

  6. heaths commented on Mar 28, 2017

    @heaths
    Member

    René Ferdinand Rivera Morell (@grafikrobot) looking at the boostorg/boost repo I see a number of bootstrap scripts that pull down files (granted, Python scripts). Perhaps the MIT license is more restrictive but you merely need to pull it. You don't even have to include it in your repo. That's why the vswhere.exe executable itself (not ZIP'd or anything) is available here on GitHub. How is pulling that different from pulling other build-required scripts?

  7. grafikrobot commented on Mar 28, 2017

    @grafikrobot

    Heath Stewart (@heaths) I'm not sure where you see the bootstrap pulling anything. As it's designed to operate entirely offline. For example it's possible to download a Boost release unplug your network cable (or equivalent) and then do a complete build. Which is actually required for some platforms like some mainframes and other specialized hardware that are not internet connected.

  8. heaths commented on Mar 28, 2017

    @heaths
    Member
  9. grafikrobot commented on Mar 28, 2017

    @grafikrobot

    Heath Stewart (@heaths) This https://github.com/boostorg/boost/blob/master/bootstrap.bat is the script that checks if you've already built the build system. If not, it tries to build it. If that fails it tells the user some alternatives.

    As for RTW people.. Good question. Boost could choose to not support it. Or only support it with a big disclaimer and some user manual configuration (i.e. we'd fail to bootstrap and the message would suggest that if they have RTW they do the manual config).

  10. grafikrobot commented on Mar 28, 2017

    @grafikrobot

    Heath Stewart (@heaths) PS.. Also for RTW customers Microsoft could choose to install vswhere as part of the next OS patch set so that everyone has it installed. Wouldn't help the customers that use OS version that are past end-of-life. But VS2017 probably doesn't run on those.

  11. OlafvdSpek commented on Mar 30, 2017

    @OlafvdSpek

    René Ferdinand Rivera Morell (@grafikrobot) Why an OS update and not just a VS update?
    And why not have users use "Developer Command Prompt for VS 2017" until MS fixes this?

    Heath Stewart (@heaths) That's what updates are for.

  12. heaths commented on Mar 31, 2017

    @heaths
    Member

    Olaf van der Spek (@OlafvdSpek) users are not forced to take updates for VS. They might have to in some scenarios, but they have never been required. Many organizations want to do rigorous testing before ever taking updates. Even if we did, some users may not be connected or take an update, which means they're on RTW.

  13. OlafvdSpek commented on Mar 31, 2017

    @OlafvdSpek

    Heath Stewart (@heaths) True, so one might decide not to support RTW..

  14. grafikrobot commented on Apr 4, 2017

    @grafikrobot

    Copying my "solution" from another issue here for the benefit of those in this topic..

    Never mind.. After trying to use the vswhere tool to determine the cl.exe location with some modicum of sanity I've given up. My current suggestion will be to avoid this tool and wait for real solution from Microsoft. In the mean time we will tell users that if they want VS2017, aka cl.exe 14.10 (or 14.1 depending on whom you ask) they will need to run from the VS command prompt or set the VS150COMNTOOLS environment variable manually.

    Thank you for my wasted time.. Goodbye.

  15. 9 remaining items

  16. res2k commented on Apr 5, 2017

    @res2k

    If you're using vcvarsall.bat you should be fine - it can be found in %dir%\VC\Auxiliary\Build (no version number, yay!).

    I think build tools for VC <= 14.0 tend use the registry to look for vcvarsall.bat anyway, so doing the same, but via vswhere.exe, is probably not a terribly impractical approach.

  17. heaths commented on Apr 5, 2017

    @heaths
    Member

    As Tim Sneath (@timsneath) mentioned we will be including vswhere in a well-known location in a subsequent release, so I'm resolving this issue.

  18. OlafvdSpek commented on Apr 6, 2017

    @OlafvdSpek

    Heath Stewart (@heaths) I'd still like to hear feedback on #41 (comment)

  19. heaths commented on Apr 6, 2017

    @heaths
    Member

    Please see my previous comment. A single variable would not capture the granularity of options or which toolset version (now that we ship multiple) and target architecture for native compilation. The suggestion by Frank Richter (@res2k) is a robust solution that will handle that.

  20. OlafvdSpek commented on Apr 6, 2017

    @OlafvdSpek

    Heath Stewart (@heaths) I know it won't, but that shouldn't stop you from allowing the user to pick one as default..

    And please see #41 (comment)

  21. 3F commented on Apr 6, 2017

    @3F
    Author

    I updated information about solutions for this issue, and you can also try this if you have similar problem for today.

    After further discussion internally, we're going to add vswhere.exe to a known location (such as %CommonProgramFiles%) in an upcoming servicing release

    Tim Sneath (@timsneath), Good ! Thanks.

  22. timsneath commented on Apr 6, 2017

    @timsneath
    Contributor

    Denis Kuzmin (@3F), this is awesome. Thanks for going the extra mile here - really appreciate it! When we update the documentation for this area, we'll be sure to link to your repo.

  23. 3F commented on Apr 6, 2017

    @3F
    Author

    Tim Sneath (@timsneath),

    we'll be sure to link to your repo

    All are welcome -_*

  24. heaths commented on Apr 20, 2017

    @heaths
    Member
  25. OlafvdSpek commented on Apr 21, 2017

    @OlafvdSpek

    What if the user uses a custom install dir?

  26. refack commented on Apr 21, 2017

    @refack

    What if the user uses a custom install dir?

    [unofficial answer] Olaf van der Spek (@OlafvdSpek) AFAIK and from own my experience, the custom install dir (which I love and always use) is for the actual VS instance. The installer is always at %ProgramFiles(x86)%\Microsoft Visual Studio\Installer

  27. 3F commented on Apr 21, 2017

    @3F
    Author

    Olaf van der Spek (@OlafvdSpek),

    As I understand, today there is no way to change path for installer:

    vs_Enterprise -h

    I see only --installPath key that defines path by default for new instance of VS, and not for installer. The installer still should be appeared in %ProgramFiles(x86)%\Microsoft Visual Studio\Installer (Win-x64) and %ProgramFiles%\Microsoft Visual Studio\Installer (Win-x32). if not, please add path via registry <_<

    well I checked this. Now we can find vswhere.exe inside this directory. Yey !

    vswhere

    Heath Stewart (@heaths), thanks for good news.

    Later I will update logic of hMSBuild for new searhing of vswhere (locally and via NuGet).

  28. heaths commented on Apr 21, 2017

    @heaths
    Member

    The installer directory is fixed to "%ProgramFilers(x86)%\Microsoft Visual Studio\Installer". If an when we ever move it, we will of course need to maintain at least a symbolic link in that location for vswhere (to other files you find in that directory we make no such guarantee).

  29. sldr commented on May 11, 2017

    @sldr

    Consider:

    @echo off
    for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [11^,12^) -property installationPath`) do (
        if exist "%%i" (
            set VS11INSTALLDIR=%%i
            set VS11VCVARSALL=%%iVC\vcvarsall.bat
        )
    )
    for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [12^,13^) -property installationPath`) do (
        if exist "%%i" (
            set VS12INSTALLDIR=%%i
            set VS12VCVARSALL=%%iVC\vcvarsall.bat
        )
    )
    for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [13^,14^) -property installationPath`) do (
        if exist "%%i" (
            set VS13INSTALLDIR=%%i
            set VS13VCVARSALL=%%iVC\vcvarsall.bat
        )
    )
    for /f "usebackq tokens=*" %%i in ("%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [14^,15^) -property installationPath`) do (
        if exist "%%i" (
            set VS14INSTALLDIR=%%i
            set VS14VCVARSALL=%%iVC\vcvarsall.bat
        )
    )
    for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [15^,16^) -property installationPath`) do (
        if exist "%%i" (
            set VS15INSTALLDIR=%%i
            set VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat
        )
    )
    REM call "%VS11VCVARSALL%"
    REM call "%VS12VCVARSALL%"
    REM call "%VS13VCVARSALL%"
    REM call "%VS14VCVARSALL%"
    REM call "%VS15VCVARSALL%" x86
    REM call "%VS15VCVARSALL%" x64
    

    Just remove REM on one of the last calls for the version you want.

    Hope this helps,
    SLDR
    (Stephen L. De Rudder)

    I know it isn't perfect... ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions