void BeforeExeQuery(object sender, EventArgs e) { OleMenuCommand button = (OleMenuCommand)sender; button.Enabled = button.Visible = false; var item = VsHelpers.GetProjectItem(_dte); if (item == null || item.FileCount == 0) { button.Enabled = button.Visible = false; return; } string path = item.FileNames[1]; if (!VsHelpers.IsValidFileName(path)) { return; } string[] allowed = new[] { ".CMD", ".BAT" }; string ext = Path.GetExtension(path).ToUpperInvariant(); bool isEnabled = allowed.Contains(ext) && File.Exists(path); button.Enabled = button.Visible = isEnabled; }
void BeforeExeQuery(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var button = (OleMenuCommand)sender; button.Enabled = button.Visible = false; ProjectItem item = VsHelpers.GetProjectItem(_dte); if (item == null || item.FileCount == 0) { return; } string path = item.FileNames[1]; if (!VsHelpers.IsValidFileName(path)) { return; } string[] allowed = { ".CMD", ".BAT", ".PS1" }; string ext = Path.GetExtension(path); bool isEnabled = allowed.Contains(ext, StringComparer.OrdinalIgnoreCase) && File.Exists(path); button.Enabled = button.Visible = isEnabled; }