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; }
private void ExecuteFile(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); ProjectItem item = VsHelpers.GetProjectItem(_dte); string path = item.FileNames[1]; string folder = Path.GetDirectoryName(path); string ext = Path.GetExtension(path); if (!string.IsNullOrEmpty(ext) && ext.ToLower() == ".ps1") { StartProcess(folder, "powershell.exe", "-ExecutionPolicy Bypass -NoExit -File \"" + Path.GetFileName(path) + "\""); } else { var options = GetDialogPage(typeof(Options)) as Options; string arguments = (options.Arguments ?? string.Empty).Replace("%folder%", folder); string confName = VsHelpers.GetSolutionConfigurationName(_dte); arguments = arguments.Replace("%configuration%", confName); string confPlatform = VsHelpers.GetSolutionConfigurationPlatformName(_dte); arguments = arguments.Replace("%platform%", confPlatform); arguments = arguments.Replace("%file%", Path.GetFileName(path)); StartProcess(folder, options.Command, arguments); } }
private void ExecuteFile(object sender, EventArgs e) { var item = VsHelpers.GetProjectItem(_dte); string path = item.FileNames[1]; string folder = Path.GetDirectoryName(path); StartProcess(folder, "cmd.exe", "/k \"" + Path.GetFileName(path) + "\""); }
private void ExecuteFile(object sender, EventArgs e) { var item = VsHelpers.GetProjectItem(_dte); string path = item.FileNames[1]; string folder = Path.GetDirectoryName(path); string ext = Path.GetExtension(path); if (!string.IsNullOrEmpty(ext) && ext.ToLower() == ".ps1") { StartProcess(folder, "powershell.exe", "-ExecutionPolicy Bypass -NoExit -File \"" + Path.GetFileName(path) + "\""); } else { StartProcess(folder, "cmd.exe", "/k \"" + Path.GetFileName(path) + "\""); } }