Accessing resources in registered .NET DLL via res

2019-08-30 06:09发布

问题:

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.