如何在同一解决方案中获取另一个项目目录?

huangapple go评论68阅读模式
英文:

How do you get another project directory in the same solution?

问题

这段文字的翻译如下:

"所以我有一个解决方案,其中有两个不同的项目(例如一个是管理项目,另一个是演示项目)。这意味着我有两个 .exe 文件。我的当前项目是演示项目,但我想要获取另一个项目(管理项目)的目录。

AppDomain.CurrentDomain.BaseDirectory

这段代码给我当前项目的目录。一种方法是回退(./)并访问另一个项目,但这将需要大量硬编码。是否有更好的方法来实现这个?"

英文:

So I have a solution witch has two different projects(for example one of them is admin and one of them is presentation). it means I have two .exe files. My current project is for example presentation but I want the directory of the other one(admin)

 AppDomain.CurrentDomain.BaseDirectory

this code gives me the current project directory. one way is to back(./) and reach to the other project but it will be too much hard code. Is there any better ways to do it

答案1

得分: 1

通常,解决方案/项目是设计时的概念,在运行时,它们只是独立的可执行文件,您可以将它们放在任何地方(例如,我假设您将它们放在c:\xxx\Admin\Project1.exec:\xxx\Presentation\Project2.exe等位置)。如果是这样,有许多可能的方法可以在运行时访问它们,其中一些包括:

  • 相对路径:如您提到的使用 ..\ 语法
  • 某种配置方式:app.config/其他配置文件(本地目录或应用程序数据等)/注册表
  • 高级模式:也许是IPC(如果两个可执行文件都在运行)
英文:

Generally solutions/projects are design time concepts, at run time these are simply independent exes that you can put wherever you want (like I assume u will be putting it in say c:\xxx\Admin\Project1.exe and c:\xxx\Presentation\Project2.exe). If so there are many possible ways to access these during runtime, some include:

  • Relative path: like you mentioned using ..\ syntax
  • Some form of config: app.config/other config file (local directory or appdata etc)/registry
  • Advanced modes: maybe IPC (works if both exe's are running)

huangapple
  • 本文由 发表于 2023年6月26日 23:32:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76558164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定