Obsidian Phoenix
Obsidian Phoenix

Reputation: 4155

Determining Installed Visual Studio Path for 2017

I have a powershell script that looks at a list of VS installations, and determines the highest version installed. It then uses the InstallDir for that version, and uses it to access various commands.

It still uses the lower versions, however.

As of VS2017, it appears that the Registry keys are no longer saved in the same way. I need to update the script to be able to figure out the 2017 settings.

#Add New Versions to this list when new versions of VS are released
$VsVersionsToDisable = "10.0", "11.0", "12.0", "14.0"

[System.Collections.ArrayList]$VsVersions = $VsVersionsToDisable

#Find the Highest installed VS Version, and use it for the TFS.exe Command.
foreach ($version in $VsVersions | Sort-Object -Descending)
{
    $keyPath = "HKCU:\Software\Microsoft\VisualStudio\$version`_Config"
    If (Test-Path $keyPath)
    {
        $aliasPath = Get-ItemProperty -Path $keyPath | Select-Object `
                            -ExpandProperty InstallDir
        $proxyPath = Join-Path $aliasPath "tf.exe"
        set-alias proxyTF $proxyPath
    }
}

To avoid an XY question: We use this script to configure the TFS Proxy settings for a user. It determines the highest installed version, uses it to find the proxy, then iterates through the lower versions configuring their proxy settings with the same value.


What is the best way to determine the installation directory (and also the tf.exe location) for VS2017?

Upvotes: 3

Views: 5949

Answers (3)

David
David

Reputation: 21

I did use this as a reference and came to a solution in another way. I'm not sure how resilient it is with regards to other versions, but it did the trick for me. It get's the directory of devenv and then I add the extra on the end for TFS. Obviously if the structure is different, then we are screwed. Hope it helps.

    $regKey = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe"
    $visualStudioDir = Get-ItemPropertyValue -Path $regKey -Name "(Default)"
    $visualStudioDir = ($visualStudioDir.Replace("devenv.exe","")).replace("`"","")
    $tfsPath = 'CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe'
    Set-Alias tf $visualStudioDir$tfsPath
    tf workspaces

Upvotes: 1

Jimmy
Jimmy

Reputation: 28396

Since you're using PowerShell, check out https://github.com/microsoft/vssetup.powershell, which is a PS module for detecting installations of VS2017+.

Otherwise, you could need to rely on the Nuget package which is the supported means of detecting VS.

See also this answer on a related question, which predates the PS module I listed above but contains some unsupported methods for finding VS.

Upvotes: 3

jessehouwing
jessehouwing

Reputation: 114796

From what I can see, use the SxS\VS7 option:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7

It should give you the root paths to Visual Studio:

enter image description here

That should get you going.

The tf.exe location is then stored using a symlink under:

.\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe

Upvotes: 8

Related Questions