У меня есть некоторые инструменты, которые выполняют обновления в .NET-решениях, но им нужно знать каталог, в котором находится решение.
Я добавил эти инструменты в качестве внешних инструментов, где они появляются в меню инструментов IDE, и поставляя $(SolutionDir)
в качестве аргумента. Это прекрасно работает.
Тем не менее, я хочу, чтобы эти инструменты были легче получить доступ в среде IDE для пользователя через пользовательское меню верхнего уровня (для которого я создал проект пакета интеграции Visual Studio) и через контекстное меню на узлах решения (для которых я создал проект надстройки Visual Studio). Я ищу способ получить текущую директорию решений через эти контексты.
Я попытался получить информацию о решении из объекта VisualStudio.DTE
:
EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
Но это возвращает каталог решений для add ins, а не текущее решение.
Я попытался повторить $(SolutionDir)
и прочесть его:
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "echo $(SolutionDir)");
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
Но это вернуло каталог для IDE, а не текущее решение.
Я не видел никакой важной информации в решении node CommandBar
.
В качестве альтернативы, если бы был способ программного доступа к определенным внешним инструментам Visual Studio и запускать их (используя уже определенные макрокоманды), это сработало бы.
Какое решение?