Accessing resources in registered .NET DLL via res protocol

落花浮王杯 提交于 2019-12-11 23:25:08

问题


I have a .NET DLL that I register with regasm.exe as a Browser Helper Object. I embedded several Win32 resources in the DLL using .res files and /win32 switch to csc.exe.

image.png   HTML    "image.png"

I am able to access the resources using the res protocol as long as I include the absolute path of the DLL.

res://C:\Path\To\My\Dll\Assembly.dll/image.png

This is rather unfortunate. I would much rather just reference the assembly name as I have seen in many other examples:

res://Assembly.dll/image.png

But this results in an error because the browser can't find the resource.

Ideas?


回答1:


I think there are a couple things that can be done. First, I believe your assembly needs to be a part of the global assembly cache if you don't want to be forced to use the full path.

Add assembly to global assembly cache.

It's not pretty and you must also keep in mind that a newer build of the DLL will be different from the version in cache. So it would essentially be another extra step to take which would just lead us back to accepting having to put in the full path in the first place.

Second, another solution I believe that works would be to place the DLL in the same directory as the VS utility or the other resources you're trying to use. This could be applicable to multiple different things that one might want to do, but requires manually moving your files around.

Third, you create some custom environmental variables that represent the path that you desire. So instead of typing the full path in the future, you just type your variable.

The third option is my favorite and something that I use for multiple different things I need to accomplish from the command-line.



来源:https://stackoverflow.com/questions/9292295/accessing-resources-in-registered-net-dll-via-res-protocol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!