我有一个包含Resources
的文件夹,我想获得一个包含所有路径
的列表。
如果我将它们设置为嵌入式资源
,我可以通过以下方式获取它们
var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
当遵循这个答案时 https://stackoverflow.com/a/1935035/6229375 , 我不应该再使用 embedded resource
或者我做错了什么?
最佳答案
来自以下blog post :
Files marked with build action of “Resource” are added to a special resx file called ProjectName.g.resx. This file is generated during the build, it is not part of the project. You can access content of the ‘Resource’ files by creating an instance of ResourceManager and calling GetStream(filename). Additionally, in WPF applications you can access these resources via Application.GetResourceStream() in C# and via things like in XAML.
var resourceManager = new ResourceManager("ConsoleApp5.g", Assembly.GetExecutingAssembly());
var resources = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true,
true);
foreach (var res in resources)
{
System.Console.WriteLine(((DictionaryEntry)res).Key);
}
其中 ((DictionaryEntry)res).Value 将是 Stream。
关于c# - 从程序集中获取所有资源的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52179108/