开发者

C# path relative to assembly DLL and not EXE [closed]

开发者 https://www.devze.com 2023-01-23 06:42 出处:网络
Closed. This question needs debugging details. It is not currently accepting answers. 开发者_如何学Python
Closed. This question needs debugging details. It is not currently accepting answers. 开发者_如何学Python

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 question

I 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);
0

精彩评论

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