Last active
March 16, 2017 17:16
-
-
Save VladimirMakaev/90e2af080b3d31a056bb01acd7433999 to your computer and use it in GitHub Desktop.
Powershell Profile that adds Visual Studio Environment to the PATH. Similar to Developer Console shortcut for Visual Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #$env:path += ";" + (Get-Item "Env:ProgramFiles(x86)").Value + "\Git\bin" | |
| #ls C:\tools\poshgit -Recurse profile.example.ps1 | select -First 1 | foreach-object { ."$($_.FullName)"} | |
| #if(Test-Path 'C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1'){ | |
| # Import-Module 'C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1' | |
| #} | |
| if(Test-Path 'c:\PSLocal'){ | |
| ls "c:\PSLocal" | Foreach-Object {Write-Host "Loading $_"; .$_.FullName} | |
| } | |
| #if(test-path 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\'){ | |
| # ls 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1' | ForEach-Object{ | |
| # Write-Host "Loading $_"; import-module $_.FullName | |
| # } | |
| #} | |
| function Clean-EnvFileCache(){ | |
| del (Join-Path $env:TEMP VsPathCache.cache) | |
| } | |
| function Apply-EnvironmentVariable($entry) | |
| { | |
| $split = $entry.split('=') | |
| $name = $split[0] | |
| $val = $split[1] | |
| if($name -ne "Path"){ | |
| Set-Item -Path "env:$($name)" -Value $val | |
| } | |
| else{ | |
| $path = (Get-Item -Path "env:$($name)").Value | |
| Set-Item -Path "env:$($name)" -Value "$($path);$($val)" | |
| } | |
| } | |
| function Get-Batchfile ($file) { | |
| $cachePath = Join-Path $env:TEMP VsPathCache.cache | |
| if(Test-Path $cachePath) | |
| { | |
| Write-Host "Loading environment variables from $cachePath" | |
| Get-Content $cachePath | ForEach-Object { Apply-EnvironmentVariable $_} | |
| }else{ | |
| if(Test-Path $file){ | |
| $cmd = "`"$file`" & set" | |
| $cachedCmd = cmd /c $cmd | |
| Set-Content -Path $cachePath -Value $cachedCmd | |
| $cachedCmd | ForEach-Object { Apply-EnvironmentVariable $_ } | |
| }else{ | |
| Write-Host -ForegroundColor Red "$file has not been found" | |
| } | |
| } | |
| } | |
| function Load-VSEnvironment() | |
| { | |
| $versionsToTry = "14.0", "12.0" | |
| $batchFile = $versionsToTry | %{"C:\Program Files (x86)\Microsoft Visual Studio $($_)\Common7\Tools\vsvars32.bat"} | Where-Object {Test-Path $_} | Select-Object -First 1 | |
| Get-Batchfile $batchFile | |
| [System.Console]::Title = "Visual Studio 14 Windows Powershell" | |
| } | |
| Load-VSEnvironment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment