Skip to content

Commit 0f0c1ff

Browse files
committed
Set-VsDevEnv
1 parent caf7cea commit 0f0c1ff

File tree

4 files changed

+70
-37
lines changed

4 files changed

+70
-37
lines changed

Microsoft.PowerShell_profile.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function prompt {
2020
# Aliases
2121

2222
New-Alias ep Edit-PSProfile
23-
New-Alias vs Invoke-VsDevCmd
23+
New-Alias vs Set-VsDevEnv
2424
New-Alias push Push-Location
2525
New-Alias pop Pop-Location
2626

@@ -78,7 +78,7 @@ New-Alias dow Start-DockerForWindows
7878

7979
# run vsdevcmd.bat if $env:vsdev is set; this is done by conemu task definition
8080
if ($env:vsdev -eq '1') {
81-
Invoke-VsDevCmd
81+
Set-VsDevEnv
8282
}
8383

8484
# Chocolatey profile (added by Chocolatey installer)

Modules/Scripts/Invoke-VsDevCmd.ps1

Lines changed: 0 additions & 32 deletions
This file was deleted.

Modules/Scripts/Set-VsDevEnv.ps1

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<#
2+
.SYNOPSIS
3+
Invoke the Visual Studio environment batch script. Should alias this with 'vs'
4+
#>
5+
6+
Begin
7+
{
8+
}
9+
Process
10+
{
11+
$script:pushed = $false
12+
13+
$0 = "${env:ProgramFiles}\Microsoft Visual Studio\2022\Professional\Common7\Tools"
14+
if (Test-Path $0)
15+
{
16+
Write-Host '... setting environment for Visual Studio 2022 Professional' -fo DarkYellow
17+
Push-Location $0
18+
$script:pushed = $true
19+
}
20+
else
21+
{
22+
$0 = "${env:ProgramFiles}\Microsoft Visual Studio\2022\Enterprise\Common7\Tools"
23+
if (Test-Path $0)
24+
{
25+
Write-Host '... setting environment for Visual Studio 2022 Enterprise' -fo DarkYellow
26+
Push-Location $0
27+
$script:pushed = $true
28+
}
29+
else
30+
{
31+
Write-Host '... cannot find Visual Studio 2022' -fo Red
32+
return
33+
}
34+
}
35+
36+
# run the VsDevCmd script and then call SET to dump the env...
37+
cmd /c "VsDevCmd.bat & SET" | foreach `
38+
{
39+
$line = $_
40+
41+
# first index only
42+
$index = $line.IndexOf('=')
43+
if ($index -gt 0 -and $index -lt $line.Length - 1)
44+
{
45+
$name = $line.Substring(0, $index)
46+
$value = $line.Substring($index + 1)
47+
48+
$def = (Get-Item env:$name -ea:SilentlyContinue).Value
49+
if ($def -eq $null -or $def -ne $value)
50+
{
51+
Write-Host ('{0,-25}' -f $name) -NoNewline
52+
Write-Host " $value" -fo DarkGray
53+
54+
Set-Item -Force -Path env:$name -Value "$value"
55+
}
56+
}
57+
}
58+
}
59+
End
60+
{
61+
if ($pushed)
62+
{
63+
Pop-Location
64+
}
65+
}

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ Convenient when you need to run as a normal user from an elevated prompt.
199199
#### [`Invoke-SuperUser`](Modules/Scripts/Invoke-SuperUser.ps1)
200200
Open a new command prompt in elevated mode. Aliased to `su`. Special command for ConEmu emulator.
201201

202-
#### [`Invoke-VsDevCmd`](Modules/Scripts/Invoke-VsDevCmd.ps1)
203-
Invoke the Visual Studio environment batch script. Aliased to `vs`
204-
205202
#### [`New-Administrator`](Modules/Scripts/New-Administrator.ps1) -Username -Password
206203
Create a new local admin user.
207204

@@ -264,6 +261,9 @@ Set full-access ownership of a specified Registry key.
264261
#### [`Set-SleepSchedule`](Modules/Scripts/Set-SleepSchedule.ps1) (-SleepTime -WakeTime) | (-Clear [-ClearTimers])
265262
Creates scheduled tasks to sleep and wake the computer at specified times.
266263

264+
#### [`Set-VsDevEnv`](Modules/Scripts/Set-VsDevEnv.ps1)
265+
Invoke the Visual Studio environment batch script. Aliased to `vs`
266+
267267
#### [`Show-ColorizedContent`](Modules/Scripts/Show-ColorizedContent.ps1) -Filename f [-ExcludeLineNumbers]
268268
Type the contents of a PowerShell script with syntax highlighting.
269269

0 commit comments

Comments
 (0)