gradle-native icon indicating copy to clipboard operation
gradle-native copied to clipboard

Gradle unable to locate Visual Studio for Visual Studio Build Tools

Open iskiselev opened this issue 6 years ago • 9 comments

Expected Behavior

Gradle should be able to locate Visual Studio when Visual Studio Build Tools only (with C++) was installed.

Current Behavior

Build fails with: Tool chain 'visualCpp' (Visual Studio): Could not locate a Visual Studio installation, using the command line tool, Windows registry or system path.

Steps to Reproduce (for bugs)

  1. Use clean VM/docker
  2. Download Visual Studio Build Tools installer (https://aka.ms/vs/15/release/vs_buildtools.exe)
  3. Install it (vs_BuildTools.exe --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81)
  4. Try to compile any C++ application

Root cause

When vswhere is executed, option -products * should be passed into it to locate any version of Visual Studio. It should be fixed here. See for reference Microsoft/vswhere#61.

iskiselev avatar Apr 13 '18 03:04 iskiselev

@iskiselev Have you looked at my issue https://github.com/gradle/gradle-native/issues/618? I feel like perhaps this is related?

For a native plugin developer, it would be nice to always be able to install the most minimum toolchain necessary. Great open issue.

gblikas avatar Apr 16 '18 20:04 gblikas

@ghale Is there an ETA for this issue? It seems to be easy to fix.

Or does anybody know a workaround? Having to install Visual Studio is not an option for me.

berntie avatar Nov 11 '19 16:11 berntie

By now I am currently using Gradle 5.4.1.. From my experience it can detect vs build installs. At least for vc 142. I managed to get vc 141 working by putting cl.exe on the Path variable.

janjoerke avatar Nov 11 '19 16:11 janjoerke

It would probably be wise to allow specifying a list of workload/component IDs to be passed as -requires arguments, too, to prevent picking up installs that are missing needed features?

(Honestly, any public API to configure the search for Visual C++ on Windows would be really nice.)

SamB avatar Dec 06 '19 20:12 SamB

By now I am currently using Gradle 5.4.1.. From my experience it can detect vs build installs. At least for vc 142. I managed to get vc 141 working by putting cl.exe on the Path variable.

I have a system with Visual Studio Build Tools 2019 version 16.4.2. Components MSVC v142 and Windows 10 SDK are installed. vswhere version 2.4.8 is on the PATH. gradle version 6.0.1 can't find the toolset.

pedrolamarao avatar Jan 13 '20 19:01 pedrolamarao

@pedrolamarao Could you execute vswhere -all -legacy -format json and post the output here. I suspect something may be wrong with the parsing of the json returned.

lacasseio avatar Jan 13 '20 19:01 lacasseio

Environment:

  • Windows 10
  • Visual Studio Installer
    • Visual Studio Build Tools 2019 (16.4.3)
      • MSVC v142 x64/x86 (v14.24)
      • Windows 10 SDK (10.0.18362.0)
  • PowerShell Core (6.2.3)
  • vswhere (2.8.4+ff0de50053)
  • Gradle (6.0.1)

Notes:

My Visual Studio Build Tools installation is extremely lean. There are no components installed beyond those indicated above.

Output:

PS C:\build-1.0> vswhere -all -legacy -format json
[]

PS C:\build-1.0> vswhere -products * -format json
[
  {
    "instanceId": "58664e5d",
    "installDate": "2020-01-06T19:08:32Z",
    "installationName": "VisualStudio/16.4.3+29709.97",
    "installationPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools",
    "installationVersion": "16.4.29709.97",
    "productId": "Microsoft.VisualStudio.Product.BuildTools",
    "productPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\LaunchDevCmd.bat",
    "state": 4294967295,
    "isComplete": true,
    "isLaunchable": true,
    "isPrerelease": false,
    "isRebootRequired": false,
    "displayName": "Ferramentas de Build do Visual Studio 2019",
    "description": "As Ferramentas de Build do Visual Studio permitem que você compile aplicativos nativos e gerenciados com base no MSBuild sem precisar do IDE do Visual Studio. Há opções para instalar as bibliotecas e os compiladores do Visual C++, MFC, ATL e suporte C++/CLI.",
    "channelId": "VisualStudio.16.Release",
    "channelUri": "https://aka.ms/vs/16/release/channel",
    "enginePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\resources\\app\\ServiceHub\\Services\\Microsoft.VisualStudio.Setup.Service",
    "releaseNotes": "https://go.microsoft.com/fwlink/?LinkId=660893#16.4.3",
    "thirdPartyNotices": "https://go.microsoft.com/fwlink/?LinkId=660909",
    "updateDate": "2020-01-17T17:51:39.0009443Z",
    "catalog": {
      "buildBranch": "d16.4",
      "buildVersion": "16.4.29709.97",
      "id": "VisualStudio/16.4.3+29709.97",
      "localBuild": "build-lab",
      "manifestName": "VisualStudio",
      "manifestType": "installer",
      "productDisplayVersion": "16.4.3",
      "productLine": "Dev16",
      "productLineVersion": "2019",
      "productMilestone": "RTW",
      "productMilestoneIsPreRelease": "False",
      "productName": "Visual Studio",
      "productPatchVersion": "3",
      "productPreReleaseMilestoneSuffix": "1.0",
      "productSemanticVersion": "16.4.3+29709.97",
      "requiredEngineVersion": "2.4.1111.43337"
    },
    "properties": {
      "campaignId": "544291046.1571058760",
      "channelManifestId": "VisualStudio.16.Release/16.4.3+29709.97",
      "nickname": "",
      "setupEngineFilePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vs_installershell.exe"
    }
  }
]

pedrolamarao avatar Jan 17 '20 17:01 pedrolamarao

Right, that explain why it's not finding it. We probably not running the right vswhere command. Maybe you could try declaring a MSVC tool chain as a workaround using C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools as the installationDir. See https://docs.gradle.org/current/userguide/native_software.html#native_binaries:tool_chain for more information on how to do it. Unfortunately that would be a work around to the problem.

lacasseio avatar Jan 17 '20 18:01 lacasseio

I have been fighting this for over two days trying to get a cpp-application to compile in a windows docker container with build tools installed. @lacasseio's fixed worked great. Can someone look at getting a fix for this?

tlf30 avatar Mar 31 '20 22:03 tlf30