开发者

How to Get the name of an executable from another project in the solution?

开发者 https://www.devze.com 2023-04-08 15:59 出处:网络
I am trying to call one executable from another. Each executable is compile开发者_StackOverflowd by its own project and both projects are in the same solution. I found this question, but that only ref

I am trying to call one executable from another. Each executable is compile开发者_StackOverflowd by its own project and both projects are in the same solution. I found this question, but that only refers to the path of the executable. I'm looking for a way to programmatically retrieve the name of the executable. I have already included 'Project 2' in 'Project 1' so I know that when I run 'Project 1' that the executable from 'Project 2' will be there, so the location isn't an issue; only the name of the executable is. Does anyone know if/how this can be done?

Thanks.


At runtime there is no longer any notion of solutions and projects and Visual Studio and stuff. At runtime you have a file system, files, inside folders, executables. So for example if you have an executable located in c:\foo\bin\Debug\foo.exe trying to read a file in c:\bar\bin\Debug\bar.txt you have to specify the absolute path to this file. Don't think in terms of Visual Studio projects. Think in terms of how your executables will be organized once you ship them to the target computer. You basically have 2 possibilities:

  • Use an absolute path to refer to a file (c:\bar\bin\Debug\bar.txt)
  • Use a relative path (in relation to the current path of the executable) to refer to a file (..\..\..\bar\bin\Debug\bar.txt)


For a bit of extra reference, a project will usually yield an executable (.exe) or assembly (*.dll) which is usually found in the bin\Debug folder for that project. The name comes from the Assembly name found under the Application tab in the project's properties (in VS2010 at least). Projects that can't be directly started will yield a *.dll file, console or winforms application should yield and *.exe.

As for programmatically finding the assembly name, this may be helpful: System.Reflection.AssemblyName.Name property

This may also be helpful: How to get the assembly (System.Reflection.Assembly) for a given type in .Net

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号