diff --git a/Posh-VsVars/Posh-VsVars.nuspec b/Posh-VsVars/Posh-VsVars.nuspec new file mode 100644 index 0000000..4ae7ee6 --- /dev/null +++ b/Posh-VsVars/Posh-VsVars.nuspec @@ -0,0 +1,43 @@ + + + + Posh-VsVars + Automatically load Visual Studio VsVars32 + 0.0.1 + Ethan J Brown + Ethan J Brown + Load Visual Studio command line tools into current shell environment + Provides cmdlets for automatically finding / loading Visual Studio variables +into the current shell session. + +By default, loads the values from the latest discovered Visual Studio version installed. + +Tip: + +Use the -Verbose switch to see what values are being imported into the current +shell session. + +Credits: + +Original concept is derived from Chris Tavares: +http://www.tavaresstudios.com/Blog/post/The-last-vsvars32ps1-Ill-ever-need.aspx +https://github.com/gzortch + +Icon from Scott Hanselman +https://github.com/shanselman +http://www.hanselman.com/blog/AwesomeVisualStudioCommandPromptAndPowerShellIconsWithOverlays.aspx + + http://github.com/Iristyle/Posh-VsVars/ + powershell shell visualstudio vs msbuild + + false + https://github.com/Iristyle/ChocolateyPackages/raw/master/Posh-VsVars/Posh-VsVars.png + + + + + + + diff --git a/Posh-VsVars/Posh-VsVars.png b/Posh-VsVars/Posh-VsVars.png new file mode 100644 index 0000000..9773514 Binary files /dev/null and b/Posh-VsVars/Posh-VsVars.png differ diff --git a/Posh-VsVars/tools/chocolateyInstall.ps1 b/Posh-VsVars/tools/chocolateyInstall.ps1 new file mode 100644 index 0000000..5b7abc8 --- /dev/null +++ b/Posh-VsVars/tools/chocolateyInstall.ps1 @@ -0,0 +1,70 @@ +$package = 'Posh-VsVars' + +function Get-CurrentDirectory +{ + $thisName = $MyInvocation.MyCommand.Name + [IO.Path]::GetDirectoryName((Get-Content function:$thisName).File) +} + +try { + $current = Get-CurrentDirectory + . (Join-Path $current 'PowerShellHelpers.ps1') + + $moduleDirectory = Get-ModuleDirectory + $installDirectory = Join-Path $moduleDirectory $package + # find user specific module directory + + # unload module if its already loaded necessary + Get-Module -Name $package | Remove-Module + + try + { + if (Test-Path($installDirectory)) + { + Remove-Item $installDirectory -Recurse -Force + } + } + catch + { + Write-Host "Could not remove existing $package folder" + } + + Write-Host "Installing $package to $installDirectory..." + $params = @{ + PackageName = $package; + Url = 'https://github.com/Iristyle/Posh-VsVars/zipball/master'; + UnzipLocation = $moduleDirectory; + } + + Install-ChocolateyZipPackage @params + + # github tarballs are versioned and we don't want that ;0 + Get-ChildItem -Path $moduleDirectory | + ? { $_.Name -match 'Posh\-VsVars' } | + Sort-Object -Property CreationTime -Descending | + Select -First 1 | + Rename-Item -NewName $installDirectory + + if (!(Test-Path $PROFILE)) + { + $profileRoot = Split-Path $PROFILE + New-Item -Path $profileRoot -Type Directory -ErrorAction SilentlyContinue + Set-Content -Path $PROFILE -Value '' -Force -Encoding UTF8 + } + + if (!(Select-String -Pattern 'Posh\-VsVars\-Profile\.ps1' -Path $PROFILE)) + { + $loaderFile = 'Posh-VsVars-Profile.ps1' + "`n`n# Load Posh-VsVars`n. '$installDirectory\$loaderFile'" | + Out-File -FilePath $PROFILE -Append -Encoding UTF8 + Write-Host 'Reloading PowerShell Profile...' + . $PROFILE + } + + Write-ChocolateySuccess $package +} +catch +{ + Write-ChocolateyFailure $package "$($_.Exception.Message)" + throw +} diff --git a/core/PowerShellHelpers.ps1 b/core/PowerShellHelpers.ps1 new file mode 100644 index 0000000..d66b2e7 --- /dev/null +++ b/core/PowerShellHelpers.ps1 @@ -0,0 +1,37 @@ +function Get-ModuleDirectory +{ + [CmdletBinding()] + param() + + # find the first default module path we can safely write to + $defaultModulePath = $Env:PSModulePath -split ';' | + ? { + Write-Verbose "Checking path $_ for write-ability" + try { + if (!(Test-Path $_)) { New-Item -Path $_ -Type Directory } + + $testFile = Join-Path $_ 'write-test.tmp' + '' | Out-File -FilePath $testFile + Remove-Item -Path $testFile + return $true + } + catch { return $false } + } | + Select -First 1 + + if ($defaultModulePath) { return $defaultModulePath } + + # no defaults were acceptable, so try Choc paths + $tools = Join-Path $Env:SystemDrive 'tools' + if ($Env:Chocolatey_Bin_Root) + { + $tools = Join-Path $Env:SystemDrive $Env:Chocolatey_Bin_Root + } + + if (!(Test-Path $tools)) + { + New-Item -Path $tools -Type Directory | Out-Null + } + + return $tools +}