C# path relative to assembly DLL and not EXE [closed]
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this questionI have an app where users can create plugins for my application and drop their dll in a /plugins folder.
The plugin developers will sometimes have to reference files (xml config files, etc) which should be stored in their respective /plugins/plugin_app/ folder.
However, it seems that when they launch my app the relative path is always set to the folder where the EXE is launched (my application). How do I solve this problem?
You need to manually add the DLL's path to form an absolute path.
For example:
string somePath = Path.Combine(typeof(PluginType).Assembly.Location, "Config.xml");
When they reference the file they can reference after appending the path components:
FileStream f = new FileStream(Path.Combine(mainAppDir,"plugins\\plugin_app\\filename.xml"),FileMode.Open);
精彩评论