Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
相对于程序集DLL而非EXE的C#路径_C#_Dll_Path_Assemblies - Fatal编程技术网

相对于程序集DLL而非EXE的C#路径

相对于程序集DLL而非EXE的C#路径,c#,dll,path,assemblies,C#,Dll,Path,Assemblies,我有一个应用程序,用户可以为我的应用程序创建插件,并将其dll放到/plugins文件夹中 插件开发人员有时必须引用文件(xml配置文件等),这些文件应存储在各自的/plugins/plugin_app/文件夹中 但是,当他们启动我的应用程序时,相对路径似乎总是设置为启动EXE的文件夹(我的应用程序)。如何解决此问题?您需要手动添加DLL的路径以形成绝对路径 例如: string somePath = Path.Combine(typeof(PluginType).Assembly.Locati

我有一个应用程序,用户可以为我的应用程序创建插件,并将其dll放到/plugins文件夹中

插件开发人员有时必须引用文件(xml配置文件等),这些文件应存储在各自的/plugins/plugin_app/文件夹中


但是,当他们启动我的应用程序时,相对路径似乎总是设置为启动EXE的文件夹(我的应用程序)。如何解决此问题?

您需要手动添加DLL的路径以形成绝对路径

例如:

string somePath = Path.Combine(typeof(PluginType).Assembly.Location, "Config.xml");

当他们引用文件时,他们可以在附加路径组件后引用:

FileStream f = new FileStream(Path.Combine(mainAppDir,"plugins\\plugin_app\\filename.xml"),FileMode.Open);

我知道这是旧的,但上面的例子是不正确的。typeof(PluginType).Assembly.Location返回程序集的路径,而不是目录。应该是Path.Combine(Path.GetDirectoryName(typeof(PluginType.Assembly.Location),“Config.xml”)