jberezanski / ChocolateyPackages

Chocolatey packages maintained by me
MIT License
86 stars 52 forks source link

Where visualstudio2019buildtools is installed? #117

Closed aminya closed 1 year ago

aminya commented 3 years ago

I am working on a project that automates setting up a Cpp development environment. I am using visualstudio2017buildtools and visualstudio2019buildtools to set up MSVC. However, my tests fail because vcvars.bat cannot find the toolset. Could you help me with this?

https://github.com/aminya/setup-cpp


    invalid parameters
    [ERROR:vcvars.bat] Toolset directory for version '15.9' was not found.
    [ERROR:VsDevCmd.bat] *** VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. ***
    [ERROR:VsDevCmd.bat] In an uninitialized command prompt, please 'set VSCMD_DEBUG=[value]' and then re-run
    [ERROR:VsDevCmd.bat] vsdevcmd.bat [args] for additional details.
    [ERROR:VsDevCmd.bat] Where [value] is:
    [ERROR:VsDevCmd.bat]    1 : basic debug logging
    [ERROR:VsDevCmd.bat]    2 : detailed debug logging
    [ERROR:VsDevCmd.bat]    3 : trace level logging. Redirection of output to a file when using this level is recommended.
    [ERROR:VsDevCmd.bat] Example: set VSCMD_DEBUG=3
    [ERROR:VsDevCmd.bat]          vsdevcmd.bat > vsdevcmd.trace.txt 2>&1

https://github.com/aminya/setup-cpp/runs/3618796745?check_suite_focus=true#step:7:302

jberezanski commented 3 years ago

https://github.com/aminya/setup-cpp/blob/7fdcafd80517c9878f7cd4b8dc0ef296a6836070/src/msvc/msvc.ts#L51

      "add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --passive",

I'm pretty certain there should be a -- before add. The way visualstudio2019buildtools package parameters parsing works is that all switches are recognized by the "--" prefix and other text (not related to a switch) is ignored. So basically the VS installer was not told to install the workload.

jberezanski commented 3 years ago

Second issue: "Microsoft.VisualStudio.Workload.NativeDesktop" is the id of the workload for the full IDE, not for Build Tools. For Build Tools you probably want the "Microsoft.VisualStudio.Workload.VCTools" workload (see https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2019&preserve-view=true#desktop-development-with-c).

jberezanski commented 3 years ago

Lastly, I suggest installing the workload using its own addon package: visualstudio2019-workload-vctools instead of passing --add in the main package parameters. This both reduces the complexity of package parameters and makes the installation more reliable in certain circumstances.

(To be clear: install both packages, first visualstudio2019buildtools (no parameters needed), then visualstudio2019-workload-vctools with --includeRecommended.)

jberezanski commented 3 years ago

After fixing the workload installation, I can see that this toolset version gets installed: 14.29.30133 (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133) but your script uses toolset = "16.11.2.0". I'm not a VC++ developer, but I believe the toolset version is something separate from the Visual Studio version, which you seem to be passing here.

From the Visual Studio Installer I can select these toolsets to install:

which suggests to me that valid toolset versions that can be passed to vcvarsall.bat are "14.29", "14.16" and "14.0"

aminya commented 3 years ago

I tried your suggestions, but the issue was not fixed. Not sure what to do. I merged some patches for now so we are one step closer to make this work.

https://github.com/aminya/setup-cpp/blob/master/src/msvc/msvc.ts

jberezanski commented 3 years ago

I suggest you try installing the packages by hand (just typing the choco commands and the vcvarsall.bat invocation into cmd) on a clean system and inspect the result. Also, I would expect the third version segment of the toolset to change rapidly (possibly with each minor VS update), so hardcoded "14.29.30133" will probably stop working once a new VS 2019 update is released. The choco packages always install the latest released VS 2017/2019 version (regardless of the package version number), so unless you are installing from a precreated offline layout (and you are not), there is no control over the exact VS version that will be installed.

jberezanski commented 3 years ago

Looking at https://github.com/aminya/setup-cpp/runs/3635436051 I can see more issues:

One more suggestion: if you enable the verbose and debug output of choco (-d -v) then the log might contain additional clues.

jberezanski commented 1 year ago

Closing due to inactivity.