Skip to content

Instantly share code, notes, and snippets.

@pedoc
Last active July 8, 2025 05:08
Show Gist options
  • Save pedoc/48dbe7a14063aab6be7dcd234e08dcf6 to your computer and use it in GitHub Desktop.
Save pedoc/48dbe7a14063aab6be7dcd234e08dcf6 to your computer and use it in GitHub Desktop.
[SmartGit]Open in Visual Studio tool
tools:
- name: Open in Visual Studio
fileStarter: {command: 'C:\Program Files\PowerShell\7\pwsh.exe', parameters: '"C:\Users\pedoc\.scripts\openVS.ps1"
"${repositoryRootPath}"'}
useForOpen: false
waitUntilFinished: false
filePattern: '*'
# Use opendef https://github.com/pedoc/minitools/releases/tag/v1.0.0.0, fast
tools:
- name: Open in Visual Studio
fileStarter: {command: opendef.exe, parameters: '-d "${repositoryRootPath}" -e sln'}
useForOpen: false
waitUntilFinished: false
filePattern: '*'
Install-Module VSSetup -Scope CurrentUser
$slnname = Get-ChildItem -Path $args[0] -Filter *.sln -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 | Select-Object -ExpandProperty FullName
switch ( $args[1] )
{
2017
{
$ver = '[15.0,16.0)'
}
2019
{
$ver = '[16.0,17.0)'
}
default
{
$ver = '[1.0,1000.0)'
}
}
$devenv = Get-VSSetupInstance | Select-VSSetupInstance -Version $ver -Latest | Select-Object -ExpandProperty InstallationPath
$devenv = $devenv + "\Common7\IDE\devenv.exe"
Start-Process -FilePath $devenv -ArgumentList $slnname
Install-Module VSSetup -Scope CurrentUser
# Parse recursion argument, default is non-recursive
$recurse = $false
if ($args.Count -ge 3 -and $args[2] -eq '-r') {
$recurse = $true
}
# Find all sln files
if ($recurse) {
$slnfiles = Get-ChildItem -Path $args[0] -Filter *.sln -Recurse -ErrorAction SilentlyContinue -Force
} else {
$slnfiles = Get-ChildItem -Path $args[0] -Filter *.sln -ErrorAction SilentlyContinue -Force
}
if ($slnfiles.Count -eq 0) {
Write-Host "No sln file found."
exit
} elseif ($slnfiles.Count -eq 1) {
$slnname = $slnfiles[0].FullName
} else {
# Popup selection dialog
$slnname = $slnfiles | Select-Object FullName | Out-GridView -Title "Please select a sln file to open" -PassThru | Select-Object -ExpandProperty FullName
if (-not $slnname) {
Write-Host "No sln file selected."
exit
}
}
switch ( $args[1] )
{
2017
{
$ver = '[15.0,16.0)'
}
2019
{
$ver = '[16.0,17.0)'
}
default
{
$ver = '[1.0,1000.0)'
}
}
$devenv = Get-VSSetupInstance | Select-VSSetupInstance -Version $ver -Latest | Select-Object -ExpandProperty InstallationPath
$devenv = $devenv + "\Common7\IDE\devenv.exe"
Start-Process -FilePath $devenv -ArgumentList $slnname
Install-Module VSSetup -Scope CurrentUser
# Parse recursion argument, default is non-recursive
$recurse = $false
if ($args.Count -ge 3 -and $args[2] -eq '-r') {
$recurse = $true
}
# Find all sln files
if ($recurse) {
$slnfiles = Get-ChildItem -Path $args[0] -Filter *.sln -Recurse -ErrorAction SilentlyContinue -Force
} else {
$slnfiles = Get-ChildItem -Path $args[0] -Filter *.sln -ErrorAction SilentlyContinue -Force
}
if ($slnfiles.Count -eq 0) {
Write-Host "No sln file found."
exit
} elseif ($slnfiles.Count -eq 1) {
$slnname = $slnfiles[0].FullName
} else {
# Custom WinForm selection dialog
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = "Select Solution File"
$form.Size = New-Object System.Drawing.Size(600,400)
$form.StartPosition = "CenterScreen"
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,10)
$listBox.Size = New-Object System.Drawing.Size(560,300)
$listBox.Font = New-Object System.Drawing.Font("Consolas", 9)
# Add files to listbox
foreach ($file in $slnfiles) {
$listBox.Items.Add($file.FullName)
}
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(400,320)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = "OK"
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(485,320)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = "Cancel"
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.Controls.AddRange(@($listBox, $okButton, $cancelButton))
$form.AcceptButton = $okButton
$form.CancelButton = $cancelButton
# Select first item by default
if ($listBox.Items.Count -gt 0) {
$listBox.SelectedIndex = 0
}
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK -and $listBox.SelectedItem) {
$slnname = $listBox.SelectedItem.ToString()
} else {
Write-Host "No sln file selected."
exit
}
}
switch ( $args[1] )
{
2017
{
$ver = '[15.0,16.0)'
}
2019
{
$ver = '[16.0,17.0)'
}
default
{
$ver = '[1.0,1000.0)'
}
}
$devenv = Get-VSSetupInstance | Select-VSSetupInstance -Version $ver -Latest | Select-Object -ExpandProperty InstallationPath
$devenv = $devenv + "\Common7\IDE\devenv.exe"
Start-Process -FilePath $devenv -ArgumentList $slnname
Install-Module VSSetup -Scope CurrentUser
# Parse recursion argument, default is non-recursive
$recurse = $false
if ($args.Count -ge 3 -and $args[2] -eq '-r') {
$recurse = $true
}
# Find all sln files
if ($recurse) {
$slnfiles = Get-ChildItem -Path $args[0] -Filter *.sln -Recurse -ErrorAction SilentlyContinue -Force
} else {
$slnfiles = Get-ChildItem -Path $args[0] -Filter *.sln -ErrorAction SilentlyContinue -Force
}
if ($slnfiles.Count -eq 0) {
Write-Host "No sln file found."
exit
} elseif ($slnfiles.Count -eq 1) {
$slnname = $slnfiles[0].FullName
} else {
# Command line selection interface
Write-Host "Multiple solution files found:"
Write-Host "================================"
for ($i = 0; $i -lt $slnfiles.Count; $i++) {
$relativePath = $slnfiles[$i].FullName.Replace($args[0], "").TrimStart('\')
Write-Host "[$($i + 1)] $relativePath"
}
Write-Host "================================"
$selection = Read-Host "Please select a file (1-$($slnfiles.Count)) or press Enter for first file"
if ([string]::IsNullOrWhiteSpace($selection)) {
$slnname = $slnfiles[0].FullName
} elseif ($selection -match '^\d+$' -and [int]$selection -ge 1 -and [int]$selection -le $slnfiles.Count) {
$slnname = $slnfiles[[int]$selection - 1].FullName
} else {
Write-Host "Invalid selection. Exiting."
exit
}
}
switch ( $args[1] )
{
2017
{
$ver = '[15.0,16.0)'
}
2019
{
$ver = '[16.0,17.0)'
}
default
{
$ver = '[1.0,1000.0)'
}
}
$devenv = Get-VSSetupInstance | Select-VSSetupInstance -Version $ver -Latest | Select-Object -ExpandProperty InstallationPath
$devenv = $devenv + "\Common7\IDE\devenv.exe"
Start-Process -FilePath $devenv -ArgumentList $slnname
@pedoc
Copy link
Author

pedoc commented Jul 8, 2025

@pedoc
Copy link
Author

pedoc commented Jul 8, 2025

openVS2.ps1 and openVS3.ps1 slowly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment