How to get Current Project Directory path using C#

后端 未结 9 843
旧巷少年郎
旧巷少年郎 2020-12-31 08:19

okay, here is the question. I have two projects one is C# Console and other is Class library. I am accessing/calling Class library method from the console app. There is a fo

9条回答
  •  暖寄归人
    2020-12-31 08:43

    Once the code is compiled and running, 'Project Path' has no meaning. All you can determine are the file locations of the compiled assemblies. And you can only do what you are asking if your Console project references the built 'class library' DLL directly, rather than via a Project Reference.

    Then, you can make use of Reflection to get Assembly paths like;

    string path = Assembly.GetAssembly(typeof (SomeClassInOtherProject)).Location;
    

提交回复
热议问题