获得在C#DLL程序集的静态文件 [英] Get static files of dll assembly in c#

查看:225
本文介绍了获得在C#DLL程序集的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Web应用程序(ASP.Net MVC 5用C#)即是可扩展的使用插件。为此,我写了一个小的SDK其中包括用户,以实现对插件加载所有接口。这是工作的罚款。

i'm writing a web application (ASP.Net MVC 5 with C#) that is extensible with plugins. For this purpose i've written a small SDK which includes all interfaces the user has to implement for the plugin to load. That's working fine.

要编写一个插件,客户在Visual Studio中创建一个新的类库项目并导入SDK组件。

To write a plugin, the customer has to create a new Class Library Project in Visual Studio and import the SDK assembly.

现在我想允许用户使用打包插件静态文件(这是目前只是一个DLL)。这些静态文件可以是HTML,CSS,JS,图片等
这些文件必须在一个特定的文件夹被我的服务器得到回升。至少,这就是我计划做的事。因此,对插件安装,我想该插件的特定文件夹中的所有文件复制到服务器的特定的插件文件夹。

Now i want to allow the user to pack static files with the plugin (which is currently just a dll). Those static files can be html, css, js, images, etc. Those files have to be in a specific folder to get picked up by my server. At least, that's what i am planning to do. So on plugin install, i want to copy all files of a specific folder of the plugin to a plugin-specific folder of the server.

问题:我如何才能获得在DLL的静态文件?我读过使用组件的GetManifestResourceNames方法,但它不工作。

The question: How can i access those static files in an dll? I've read to use the GetManifestResourceNames method of the assembly but it's not working.

有关测试,我这样做:

var assembly = Assembly.LoadFrom(pluginPath);
log.Debug("Number of ressources: " + assembly.GetManifestResourceNames().Length);
foreach(var resName in assembly.GetManifestResourceNames())
{
   log.Debug(resName);
}

但输出始终是ressources数:0。所以GetManifestResourceNames返回一个空数组

But the output is always "Number of ressources: 0" so GetManifestResourceNames returns an empty array.

我知道插件装入正确,因为我可以访问所有它的类之类的东西。难道我做错了什么?我很新的C#,因为我主要是Java开发。

I know the plugin is loaded correctly because i can access all it's classes and stuff. Am i doing something wrong? I'm quite new to C# because i am primary a Java developer.

非常感谢您的帮助!

推荐答案

我创建了一个小的测试项目,你的code正常工作,正确地上市资源的名称。

I created a small test project and your code worked fine, listing the names of the resources correctly.

这是可能你没有正确添加静态文件。当您将静态文件添加到项目中,请确保您更改建立在属性窗口中操作为嵌入的资源。

It's possible you're not adding the static files correctly. When you add the static files to the project, ensure you change Build Action to be "Embedded Resource" in the properties window.

这篇关于获得在C#DLL程序集的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆