Skip to content

Need to modify UTILS.PSM1 to allow for VS 2022 builds. #29

Description

@kpff-sanderson

I modified the file 'utils.psm1' in the 'ps_modules' folder to allow for builds on VS2022. See comments in code below:

#Get-VSPath new code
function Get-VSPath {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [string]$Version)
    BEGIN { Import-Module -Name $PSScriptRoot\VSSetup\Microsoft.VisualStudio.Setup.PowerShell.dll }
    PROCESS {
        Trace-VstsEnteringInvocation $MyInvocation
        try {
	     ##Added this section to cover VS2022
	    if ($Version -eq "17.0" -and
                ($instance = Get-VSSetupInstance | Select-VSSetupInstance -Version '[17.0,)') -and
                $instance.installationPath) {
				Write-Verbose "Using v17.0 path: $instance.installationPath"
                return $instance.installationPath
            }
            ##Added above section to cover VS2022

            if ($Version -eq "16.0" -and
                ($instance = Get-VSSetupInstance | Select-VSSetupInstance -Version '[16.0,)') -and
                $instance.installationPath) {
				Write-Verbose "Using v16.0 path: $instance.installationPath"
                return $instance.installationPath
            }
            
            # Search for a 15.0 Willow instance.
            #Modified the '-Version' argument from '[15.0,16.0,)' to '[15.0,)' to prevent duplicates.
            if ($Version -eq "15.0" -and
                ($instance = Get-VSSetupInstance | Select-VSSetupInstance -Version '[15.0,)') -and
                $instance.installationPath) {
				Write-Verbose "Using v15.0 path: $instance.installationPath"
                return $instance.installationPath
            }

            # Fallback to searching for an older install.
            if ($path = (Get-ItemProperty -LiteralPath "HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\$Version" -Name 'ShellFolder' -ErrorAction Ignore).ShellFolder) {
				Write-Verbose "Using fallback path: $path"
                return $path
            }
        }
        finally {
            Trace-VstsLeavingInvocation $MyInvocation
        }
    }
    END { }
}

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions