问题描述
方案A:
在某些.NET核心项目中的MyLib.csproj
项目文件namespace MyLib
中进行测试,
嵌入这样的资源,其中包括ProjectPath/data/
下的所有文件:
<ItemGroup>
<EmbeddedResource Include="data\**" />
</ItemGroup>
然后:
// names,attains all the resource file names under "ProjectPath/data/"
string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
方案A工作正常;
场景B:
创建了一个Unity3D游戏项目,导入了一些程序包,这些文件包带有自动生成的Game.sln
和“ ProjectPath /”下的许多.csproj
文件。
在一个项目文件MyLib.csproj
中,我使用正确的路径执行了相同的操作:
<ItemGroup>
<EmbeddedResource Include="Assets\Mylib\data\**" />
</ItemGroup>
单击Game.sln
进入Visual Studio,在MyLib
程序集下进行确认,正确显示“ Assets \ Mylib \ data”下的所有资源文件,在文件File Properties
中进行确认,其为{{ 1}}。
由于在这个Unity3D游戏项目中,Build Action : Embedded Resource
程序集不再是MyLib
了,所以我试图找到该程序集:
ExecutingAssembly
现在Assembly myLibAssembly = null;
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExcutingAssembly().Location);
foreach(var path in Directory.GetFiles(assemblyFolder,"*.dll"))
{
if(path.Contains("MyLib")) myLibAssembly = Assembly.LoadFrom(path);
}
// Try to get the resource names here,but couldn't
// names is empty here
string[] names = myLibAssembly.GetManifestResourceNames();
为空。
我想知道我嵌入的资源是否存储在esle某个地方;
我再次尝试:
names
因此,在此多组件Unity3D游戏解决方案中,我嵌入的资源(标记为foreach(var path in Directory.GetFiles(assemblyFolder,"*.dll"))
{
// Get all the assemblies
Assembly tempAssembly = Assembly.LoadFrom(path);
// Get all the resource names from the assembly
string[] allNames = tempAssembly.GetManifestResourceNames();
// No luck here.(I didn't embed any resource in other assembly anyway)
// Just want to know if the resources I embedded are floating anywhere.
if(allNames.Length > 0) Debug.Log("Resource found!");
}
)无处不在。
我知道我对项目构建文件的了解是有限的,但是如果资源标记为Build Action : Embedded Resource
,理论上应该将其存储在正确的位置吗?
也许Unity3D的构建结构有点复杂,原始的嵌入方式无法正常工作?
(即使我通过使用程序集Properties-> Resource.resx Build Action : Embedded Resource
找到了解决方法,我仍然想知道嵌入式资源不起作用的原因,[1]:{{ 3}})
我真的相信原始的嵌入式资源方式Properties.Resource.myFile
应该可以正常工作,真的需要帮助来解决它,谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)