获取同一解决方案中的其他可执行的应用程序的路径 [英] Get application path of another executable within same solution
问题描述
我使用C#,VS 2005。
I am using c#, VS 2005.
我有一个解决方案有两个项目。
I have one solution with two projects.
PROJECT1需要一些检查后,启动项目2。
Project1 needs to startup project2 after some checks.
我如何获得Project2中的可执行文件路径从内部PROJECT1?
How do I get the executable path of Project2 from within Project1?
我需要调试和现场模式的解决方案。
I need a solution for both debug and live mode.
感谢,
KS
推荐答案
该EXE的第二个项目需要有一个可预测的位置,距离1号EXE相对的。获取包含您的第一个EXE文件夹的绝对路径很简单:
The EXE for the 2nd project needs to have a predictable location, relative from the 1st EXE. Getting the absolute path for the folder that contains your first EXE is easy:
string myPath = System.Reflection.Assembly.GetEntryAssembly().Location;
string myDir = System.IO.Path.GetDirectoryName(myPath);
然后添加你的第二EXE的相对路径。在同一目录作为第一保持其强大的建议:
Then append the relative path of your 2nd EXE. Keeping it in the same directory as the 1st is strong recommended:
string path = System.IO.Path.Combine(myDir, "project2.exe");
System.Diagnostics.Process.Start(path);
要得到这个在IDE中很好地工作以及在目标机是最简单的方法让IDE副本project2.exe。右击Project,添加引用,项目选项卡,选择Project2中。使project2.exe在同一目录PROJECT1.EXE
The easiest way to get this to work well in the IDE as well as on the target machine is to let the IDE copy project2.exe. Right-click project1, Add Reference, Projects tab, select Project2. The Copy Local property of the reference will be True so that project2.exe ends up in the same directory as project1.exe
这篇关于获取同一解决方案中的其他可执行的应用程序的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!