什么是资源名称的清单资源(Assembly.GetManifestResourceStream)? [英] What is the Resource Name for a Manifest Resource (Assembly.GetManifestResourceStream)?

查看:212
本文介绍了什么是资源名称的清单资源(Assembly.GetManifestResourceStream)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经嵌在我的ASP.NET MVC应用程序的资源(XSD文件)。现在,我想检索code这个文件。

I've embedded a resource (an XSD file) in my ASP.NET MVC application. Now, I'd like to retrieve this file from code.

看着为 Assembly.GetManifestResourceStream的文档() ,它需要一个字符串参数,它是清单资源被要求区分大小写的名称。

Looking at the documentation for Assembly.GetManifestResourceStream(), it takes a string argument that is the "case-sensitive name of the manifest resource being requested".

好了,我不觉得这非常有帮助,当然,也没有例子可以在MSDN上找到。什么是体现资源的名称?它是该文件的名称?它是该文件的完整路径和名称?抑或是提供给资源本身,如果是这样,我怎么设置一个独立的名称叫什么名字?

Well, I don't find that very helpful and, of course, there was no example to be found on MSDN. What is the name of the manifest resource? Is it the name of the file? Is it the full path and name of the file? Or is it a separate name that is given to the resource itself and, if so, how do I set that name?

推荐答案

如果我没记错的话,它的组装加上文件的全名的名称(包括扩展名),它们之间一个点。

If I remember correctly, it's the name of the assembly plus the full name of the file (extension included), with a dot between them.

一个快速的方法来找出肯定的:使用<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcenames.aspx">Assembly.GetManifestResourceNames方法:

A quick way to find out for sure: use the Assembly.GetManifestResourceNames method:

string[] result = myAssembly.GetManifestResourceNames();

...和检查的结果在调试器中的内容。

... and inspect the contents of result in the debugger.

ETA:哎呀,如果你只有一个资源,你可以只用这个code得到的名称:

ETA: Heck, if you only have one resource, you could just use this code to get the name:

string name = myAssembly.GetManifestResourceNames()[0];

我不建议,但我发现,有时候VS会创建空资源文件,并将其编译成汇编,所以你可能有更多的集资源比你想象的。

I don't recommend that, though: I've found that sometimes VS will create empty resource files and compile them into the assembly, so you might have more assembly resources than you think.

这篇关于什么是资源名称的清单资源(Assembly.GetManifestResourceStream)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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