Skip to content

Instantly share code, notes, and snippets.

@bradwilson
Last active January 23, 2018 19:05
Show Gist options
  • Save bradwilson/6e169abcef7899f01db314dd95d8812c to your computer and use it in GitHub Desktop.
Save bradwilson/6e169abcef7899f01db314dd95d8812c to your computer and use it in GitHub Desktop.
VS 2017 PowerShell script; if you need invoke-cmdscript, it's here: https://gist.github.com/bradwilson/3fca203370d54304eff1cce21ffc32aa
param(
[string]$edition,
[switch]$noWeb = $false
)
# Try and find a version of Visual Studio in the expected location, since the VS150COMNTOOLS environment variable isn't there any more
$basePath = join-path (join-path ${env:ProgramFiles(x86)} "Microsoft Visual Studio") "2017"
if ((test-path $basePath) -eq $false) {
write-warning "Visual Studio 2017 is not installed."
exit 1
}
if ($edition -eq "") {
$editions = (get-childitem $basePath | where-object { $_.PSIsContainer })
if ($editions.Count -eq 0) {
write-warning "Visual Studio 2017 is not installed."
exit 1
}
if ($editions.Count -gt 1) {
write-warning "Multiple editions of Visual Studio 2017 are installed. Please specify one of the editions ($($editions -join ', ')) with the -edition switch."
exit 1
}
$edition = $editions[0]
}
$path = join-path (join-path (join-path $basePath $edition) "Common7") "Tools"
if ((test-path $path) -eq $false) {
write-warning "Visual Studion 2017 $edition could not be found."
exit 1
}
$cmdPath = join-path $path "VsDevCmd.bat"
if ((test-path $cmdPath) -eq $false) {
write-warning "File not found: $cmdPath"
exit 1
}
invoke-cmdscript $cmdPath
if ($noWeb -eq $false) {
$path = join-path (join-path (join-path $basePath $edition) "Web") "External"
if (test-path $path) {
$env:Path = $env:Path + ";" + $path
} else {
write-warning "Path $path not found; specify -noWeb to skip searching for web tools"
}
}
param(
[string]$edition,
[switch]$noWeb = $false
)
$basePath = join-path (join-path ${env:ProgramFiles(x86)} "Microsoft Visual Studio") "Preview"
if ((test-path $basePath) -eq $false) {
write-warning "Visual Studio Preview is not installed."
exit 1
}
if ($edition -eq "") {
$editions = (get-childitem $basePath | where-object { $_.PSIsContainer })
if ($editions.Count -eq 0) {
write-warning "Visual Studio Preview is not installed."
exit 1
}
if ($editions.Count -gt 1) {
write-warning "Multiple editions of Visual Studio 2017 are installed. Please specify one of the editions ($($editions -join ', ')) with the -edition switch."
exit 1
}
$edition = $editions[0]
}
$path = join-path (join-path (join-path $basePath $edition) "Common7") "Tools"
if ((test-path $path) -eq $false) {
write-warning "Visual Studion Preview $edition could not be found."
exit 1
}
$cmdPath = join-path $path "VsDevCmd.bat"
if ((test-path $cmdPath) -eq $false) {
write-warning "File not found: $cmdPath"
exit 1
}
invoke-cmdscript $cmdPath
if ($noWeb -eq $false) {
$path = join-path (join-path (join-path $basePath $edition) "Web") "External"
if (test-path $path) {
$env:Path = $env:Path + ";" + $path
} else {
write-warning "Path $path not found; specify -noWeb to skip searching for web tools"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment