ChocolateyPackages icon indicating copy to clipboard operation
ChocolateyPackages copied to clipboard

Add/modify functions to use the --config paramter of vs_installer

Open mkr-schleupen opened this issue 3 years ago • 6 comments

Currently there seems no option to e.g. call vs_installer.exe modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" --config "MyConfig.vsconfig".

This would be a nice addition to use the logging and error handling infrastructure of the module for applying own configurations.

mkr-schleupen avatar Jun 14 '22 08:06 mkr-schleupen

How would you use this functionality in the context of Chocolatey packages? Would you install any of the existing product or workload packages (e.g. visualstudio2022enterprise or visualstudio2022-workload-manageddesktop) with the additional parameter or would you create your own package for applying your customized config?

jberezanski avatar Aug 03 '22 15:08 jberezanski

We use chocolatey in combination with puppet to build developer machines. There is a base installation module for studio, and depending on the type of machine needed, we use additional modules to enrich the installation.

mkr-schleupen avatar Aug 04 '22 05:08 mkr-schleupen

I think you should be able to achieve your goal by crafting a package which would call Add-VisualStudioComponent with a component id which could be applied on all of your machines, such as Microsoft.Component.MSBuild. Then you could install that package passing --installPath and --config via package parameters and they would be forwarded to the VS Installer. Or your package could overwrite the environment variable which normally holds the package parameters passed from Chocolatey ($Env:chocolateyPackageParameters) so that the package would be self-sufficient and not rely on a specific way of installing it. You could even embed the config file in the package.

jberezanski avatar Aug 04 '22 16:08 jberezanski

A rough sketch of the install script of the hypothetical package:

if ($Env:chocolateyPackageParameters -notlike '*--config*')
{
    $configPath = Join-Path -Path $Env:ChocolateyPackageFolder -ChildPath MyConfig.vsconfig
    $Env:chocolateyPackageParameters = $Env:chocolateyPackageParameters + " --config $configPath"
}

Add-VisualStudioComponent `
    -PackageName 'mycompany-vsconfig-flavor1' `
    -Component 'Microsoft.Component.MSBuild' `
    -VisualStudioYear '2022' `
    -Preview $false `
    -ApplicableProducts @('Community', 'Professional', 'Enterprise')

jberezanski avatar Aug 04 '22 16:08 jberezanski

Thank you for the ideas. I will try to go this way.

mkr-schleupen avatar Aug 05 '22 06:08 mkr-schleupen

Since version 1.11.0, functions in chocolatey-visualstudio.extension support a new parameter: -DefaultParameterValues <hashtable> (example), which should provide an easier way of achieving this.

jberezanski avatar Feb 03 '24 19:02 jberezanski