Skip to content

Commit a3e9183

Browse files
Add Dev PowerShell preset and improve resource cleanup
--- - 🛠️ Added "Dev PowerShell" preset using Launch-VsDevShell.ps1 in Options.cs - 🧹 Implemented Dispose override in OpenCommandLinePackage.cs to clean up _dte and Instance - 🛡️ Improved null-checking in ExecuteFile to prevent errors when no ProjectItem is found Fixes #96 Fixes #82
1 parent 9735686 commit a3e9183

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/OpenCommandLine/OpenCommandLinePackage.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,27 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
6565
mcs.AddCommand(exeItem);
6666
}
6767

68+
protected override void Dispose(bool disposing)
69+
{
70+
if (disposing)
71+
{
72+
_dte = null;
73+
Instance = null;
74+
}
75+
76+
base.Dispose(disposing);
77+
}
78+
6879
private void ExecuteFile(object sender, EventArgs e)
6980
{
7081
ThreadHelper.ThrowIfNotOnUIThread();
7182

7283
ProjectItem item = VsHelpers.GetProjectItem(_dte);
84+
if (item == null)
85+
{
86+
return;
87+
}
88+
7389
string path = item.FileNames[1];
7490
string folder = Path.GetDirectoryName(path);
7591

‎src/OpenCommandLine/Options.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ private static void InitializePresets()
3232
string devPromptFile = installDir != null
3333
? Path.Combine(installDir, @"..\Tools\VsDevCmd.bat")
3434
: "";
35+
string launchDevShellPs1 = installDir != null
36+
? Path.Combine(installDir, @"..\Tools\Launch-VsDevShell.ps1")
37+
: "";
3538

3639
_defaultPresets["cmd"] = new Command("cmd.exe");
3740
_defaultPresets["Dev Cmd Prompt"] = new Command("cmd.exe", "/k \"" + devPromptFile + "\"");
41+
_defaultPresets["Dev PowerShell"] = new Command("powershell.exe", "-ExecutionPolicy Bypass -NoExit -File \"" + launchDevShellPs1 + "\"");
3842
_defaultPresets["PowerShellCore"] = new Command("pwsh.exe", "-ExecutionPolicy Bypass -NoExit");
3943
_defaultPresets["PowerShell"] = new Command("powershell.exe", "-ExecutionPolicy Bypass -NoExit");
4044
_defaultPresets["PowerShell ISE"] = new Command("powershell_ise.exe");

0 commit comments

Comments
 (0)