【发布时间】:2010-01-13 03:29:11
【问题描述】:
我有一些对 .NET 解决方案执行更新的工具,但他们需要知道解决方案所在的目录。
我将这些工具添加为外部工具,它们出现在 IDE 工具菜单中,并提供 $(SolutionDir) 作为参数。这很好用。
但是,我希望通过自定义顶级菜单(为此我创建了 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);
但是,这会返回插件的解决方案目录,而不是当前解决方案。
我尝试回显 $(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 的目录,而不是当前的解决方案。
我在解决方案节点CommandBar中没有看到任何相关信息。
或者,如果有一种方法可以以编程方式访问已定义的 Visual Studio 外部工具并启动它们(使用已定义的宏参数),那也可以。
解决办法是什么?
【问题讨论】:
-
2+ 显然我在这里跟踪你这个疯狂的 DTE 哈哈
标签: c# visual-studio solution envdte vs-extensibility