jberezanski / ChocolateyPackages

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

Visual Studio workload packages pass "--installPath" uncoditionally #110

Closed DziubanMaciej closed 3 years ago

DziubanMaciej commented 3 years ago

The choco following command fails installation (specified paths are correct):

choco install "visualstudio2019-workload-nativedesktop" -y --packageparameters="--path shared=`"D:\Programs\VisualStudio\Shared`" --installPath=`"D:\Programs\VisualStudio\2019`""

For full log, please see attached chocolatey.log file. The important part is:

[ERROR] - ERROR: Running ["C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify --installPath=D:\Programs\VisualStudio\2019 --installPath D:\Programs\VisualStudio\2019 --path shared=D:\Programs\VisualStudio\Shared --includeRecommended --quiet --norestart --add Microsoft.VisualStudio.Workload.NativeDesktop] was not successful. Exit code was '87'. See log for possible error messages.

I'm pretty sure this is because of duplicate "--installPath" parameters being passed to the native installer. One comes from package parameters and the second from the package itself. I would expect the package to drop the latter, when the former is specified.

I have only one VS installation on my system, so I can just drop it from package parameters (command below works), but this would be a bug in a multi-installation setup.

choco install "visualstudio2019-workload-nativedesktop" -y --packageparameters="--path shared=`"D:\Programs\VisualStudio\Shared`""
jberezanski commented 3 years ago

The duplicate installPath looks like a bug, however, it might be a harmless one - I routinely use --installPath with workload packages and I've never encountered such a failure before.

On the other hand, https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2019 states that "--path shared=..." is accepted only during the first installation of VS, so this might be what's causing the error 87.

DziubanMaciej commented 3 years ago

I would think so too, if it didn't succeed without the "--installPath" parameter. Anyway, I tried removing "--path shared=...", but it didn't change anything, still error 87.

choco install "visualstudio2019-workload-nativedesktop" -y --packageparameters="--installPath=`"D:\Programs\VisualStudio\2019`""

Maybe it happens only in setups with a single VS installation? Do you have multiple?

jberezanski commented 3 years ago

Whenever a new VS 2019 Preview version is released I test it by installing all VS products one after another, each with a different installPath. However, that test does not include installing any workloads, so if the bug affects workloads only, that would explain why I had not discovered it earlier.

It's still strange because I had explicitly tested installing a VS product with several workloads to a custom path a couple of months ago (I can't remember if it was with extension version 1.8.1 or 1.9.0, though).

Anyway, I'll be able to do something about it once I return from vacation - in a week or so.

DziubanMaciej commented 3 years ago

Yup, it's probably related to workloads only, I didn't have any problems with installing VS itself.

Didn't want to interrupt anything, have a great time on your vacation!

jberezanski commented 3 years ago

Ah, there's the problem:

choco install "visualstudio2019-workload-nativedesktop" -y --packageparameters="--installPath=`"D:\Programs\VisualStudio\2019`""

Running 'Start-VSServicingOperation' for visualstudio2019-workload-nativedesktop with silentArgs:'modify --installPath=D:\Programs\VisualStudio\2019 --installPath D:\Programs\VisualStudio\2019

If you look closely, the difference between the two seemingly identical parameters is in the equals symbol (=).

The syntax of VS package parameters (and the VS installer) is such that the parameter name is always separated from the parameter value by spaces, not by "=". The only place where the equals symbol appears is in the possible values of the --path parameter (but still, it is inside the value, not as a separator between parameter name and value).

As such, the packages do not contain any logic for recognizing the = symbol and simply split the parameters string by the delimiter -- (space and two dashes)*. Therefore, the entire string installPath=D:\Programs\VisualStudio\2019 is treated as the parameter name and (because it does not match any parameter names the package script cares about) is passed unmodified to the VS Installer.

To sum up - please fix your choco invocation as follows:

choco install "visualstudio2019-workload-nativedesktop" -y --packageparameters="--installPath D:\Programs\VisualStudio\2019"

* the second benefit of this simple syntax is that paths with spaces do not need to be quoted in any way; this will work as expected: --package-parameters "--installPath D:\Path with spaces\Visual Studio 2019 Enterprise --includeRecommended"

DziubanMaciej commented 3 years ago

Wow, feeling dumb now... 😄 Thank you very much for the explanation, it works like a charm.