feat(Posh-VsVars): version 0.0.1
- Includes new set of PowerShellHelpers to find standard module directory
This commit is contained in:
43
Posh-VsVars/Posh-VsVars.nuspec
Normal file
43
Posh-VsVars/Posh-VsVars.nuspec
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<metadata>
|
||||
<id>Posh-VsVars</id>
|
||||
<title>Automatically load Visual Studio VsVars32</title>
|
||||
<version>0.0.1</version>
|
||||
<authors>Ethan J Brown</authors>
|
||||
<owners>Ethan J Brown</owners>
|
||||
<summary>Load Visual Studio command line tools into current shell environment</summary>
|
||||
<description>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
|
||||
</description>
|
||||
<projectUrl>http://github.com/Iristyle/Posh-VsVars/</projectUrl>
|
||||
<tags>powershell shell visualstudio vs msbuild</tags>
|
||||
<!-- Eula is in installer
|
||||
<licenseUrl></licenseUrl>
|
||||
-->
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<iconUrl>https://github.com/Iristyle/ChocolateyPackages/raw/master/Posh-VsVars/Posh-VsVars.png</iconUrl>
|
||||
<releaseNotes></releaseNotes>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="tools\**" target="tools" />
|
||||
<file src="..\core\PowerShellHelpers.ps1" target="tools" />
|
||||
</files>
|
||||
</package>
|
BIN
Posh-VsVars/Posh-VsVars.png
Normal file
BIN
Posh-VsVars/Posh-VsVars.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
70
Posh-VsVars/tools/chocolateyInstall.ps1
Normal file
70
Posh-VsVars/tools/chocolateyInstall.ps1
Normal file
@@ -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
|
||||
}
|
37
core/PowerShellHelpers.ps1
Normal file
37
core/PowerShellHelpers.ps1
Normal file
@@ -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
|
||||
}
|
Reference in New Issue
Block a user