开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜