开发者

Adding resources to an existing assembly

开发者 https://www.devze.com 2023-02-14 03:00 出处:网络
I have a COM Interop DLL that I\'m automatically generating from an existing COM DLL, using tlbimp.What I need is to add Details to the DLL\'s Properties dialog for file version, copyright info, etc.

I have a COM Interop DLL that I'm automatically generating from an existing COM DLL, using tlbimp. What I need is to add Details to the DLL's Properties dialog for file version, copyright info, etc.

I found some sample code that uses the AssemblyBuilder.SetCustomAttribute() API to 开发者_Python百科dynamically set AssemblyCopyrightAttribute, etc.

However, the AssemblyBuilder instance in use comes from AppDomain.CurrentDomain.DefineDynamicAssembly(), which appears to only create new assemblies. (Indeed, whenever I try that code with my DLL name, it deletes my DLL and creates a new one.)

Is there any way to get an instance of AssemblyBuilder for an existing assembly?


No, you're fundamentally looking for the wrong solution. What you see in explorer's Details tab is actually an unmanaged resource. The C# compiler auto-generates one from the assembly attributes (/win32res compiler option), this of course does not happen when you create an interop assembly. Or for that matter try to create one with an AssemblyBuilder.

To make this work, you first have to disassemble the interop library with ildasm.exe /out. Next, you have to create a version resource, best done with a C++ project. Use the resource editor to add a Version resource. After building you get a .res file. Then use ilasm.exe to re-create the interop library, using the /resource option to get the .res file embedded.

I gave you the 100 miles per hour version, this is hard to automate.


There is no need to jump the many hoops Hans mentions just to add an unmanaged resource to a PE file. Create a version resource in-memory — it's not very difficult — and use Win32 BeginUpdateResource&co. to add this resource to the .exe file produced by tlbimp.

0

精彩评论

暂无评论...
验证码 换一张
取 消