Hi all,
I’m having some trouble working with relative paths in libraries.
I created a library called “ReadJson” that takes an absolute or relative path as input and returns a JSON object. It works fine with absolute paths.
However, I’d like it to work with relative paths as well, and that’s where I’m running into issues. After reading through some forums and documentation, I realized that when a library is published and then installed in a project, using a relative path will refer to the library’s package location — not the location of the project that’s calling the library.
I’ve tried several methods to get the path of the calling project, because my goal is for the library to dynamically resolve paths relative to the main project (not the library location). Here are the approaches I tried:
System.Environment.CurrentDirectory
Directory.GetCurrentDirectory
Path.GetDirectoryName(Environment.CurrentDirectory)
Unfortunately, none of these gave me the result I expected.
Could someone please help me figure out how to properly handle relative paths in this case?
Thanks a lot!
