PowerShell and Visual Studio tools

When Visual Studio is installed it has special command prompts with tools in PATH variables such as VS2012 x86 Native Tools Command Prompt

I wrote similar scripts for PowerShell (inspired by this)

#requires -version 2

  [string] $version = "11.0"

$vsToolsPath = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio $version\VC"
$setVariablesBatch = 'vcvarsall.bat'

if (!(Test-Path $vsToolsPath)) {
    throw "Visual Studio $version tools path $vsToolsPath not found."

Push-Location "$vsToolsPath"

if (!(Test-Path $setVariablesBatch)) {
    throw "$vsToolsPath\$setVariablesBatch batch not found."

cmd /c "$setVariablesBatch & set" | ForEach-Object {
  if ($_ -match "=") {
    $variablePair = $_ -split "="
    $name = $variablePair[0]
    $value = $variablePair[1]
    Set-Item -Force -Path "ENV:\$name" -Value "$value"
Write-Host "`nVisual Studio $version Command Prompt variables set." -ForegroundColor Yellow

About mnaoumov

Senior .NET Developer in Readify
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s