简体   繁体   English

如何从dte获取到exe文件夹的项目路径

[英]How to get project path to exe folder from dte

I write a Visual Studio Extension (Vsix).我编写了一个 Visual Studio 扩展(Vsix)。

What I have done so far:到目前为止我做了什么:

  1. I have a console app which display a generated string when is executed我有一个控制台应用程序,它在执行时显示生成的字符串
  2. The Console App is being running from my plugin.控制台应用程序正在从我的插件运行。 -> i need that path to start process in different way to get output from the console. -> 我需要该路径以不同的方式启动进程以从控制台获取输出。

I need to find current running external project path to exe.我需要找到当前运行的外部项目路径到 exe。

My code:我的代码:

  private void Execute(object sender, EventArgs e)
    {
        ThreadHelper.ThrowIfNotOnUIThread();

        // This runs my external console application
        dte.Solution.SolutionBuild.Run();

        Path.GetDirectoryName(dte.Solution.FullName);
        Project prj = dte.Solution.Projects.Item(1);
        string  msg2, msg3 = "";
        msg2 = prj.DTE.FullName;
        msg3 = prj.DTE.FileName;
      
    }

Currently project which runs application is devenv.exe so:当前运行应用程序的项目是devenv.exe所以:

Path.GetDirectoryName(dte.Solution.FullName) = "D:\\user\\proj\\projName\\Docs\\App\\AppName" Path.GetDirectoryName(dte.Solution.FullName) = "D:\\user\\proj\\projName\\Docs\\App\\AppName"

I need path to exe..我需要exe的路径..

msg2, msg3 = "D:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe" msg2, msg3 = "D:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe"

Do you have any hints?你有什么提示吗?

Maybe you could use ProcessModule.ModuleName to get the full path of current process.也许您可以使用ProcessModule.ModuleName来获取当前进程的完整路径。

I create a visual studio extension with a menu command, and add this code into Execute method我使用菜单命令创建了一个 Visual Studio 扩展,并将此代码添加到 Execute 方法中

        private void Execute(object sender, EventArgs e)

        {

            ThreadHelper.ThrowIfNotOnUIThread();

           

            string message = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            string title = "Command1";

           

            ...

        }

The result:结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM