/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { var project = SolutionExplorer.GetSelectedProject(); var path = project?.FullName; if (String.IsNullOrEmpty(path)) { return; } // retrieve current project configuration (Debug|Release) and platform (x86|x64|AnyCPU) var configuration = project.ConfigurationManager.ActiveConfiguration; // retrieve current project target path, based upon the currently selected configuration var configurationName = configuration.ConfigurationName; var platformName = configuration.PlatformName; var targetFolder = GetTargetFolder(path, configurationName, platformName); // remove space from Visual Studio's "Any CPU" platform // so as to be mapped to MSBuild's "AnyCPU" platform. if (targetFolder.Length == 0 && platformName == "Any CPU") { targetFolder = GetTargetFolder(path, configurationName, "AnyCPU"); } // run PowerShell prompt at the target location const string program = @"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"; const string arguments = "/nologo /noexit /encodedCommand {0}"; var command = $"Set-Location \"{targetFolder}\""; var encodedCommand = Convert.ToBase64String(Encoding.Unicode.GetBytes(command)); var prog = Environment.ExpandEnvironmentVariables(program); var options = String.Format(arguments, encodedCommand); var process = new System.Diagnostics.Process(); process.StartInfo.FileName = prog; process.StartInfo.Arguments = options; process.StartInfo.WorkingDirectory = targetFolder; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = false; process.Start(); }