简体   繁体   中英

Do I need to rebuild and redeploy every time I upgrade a COM library used from my dotNet app?

I have a C# .net 2.0 windows app that uses a COM component. Visual Studio 2005 automatically adds an interop assembly DLL when I add the reference to this COM library.

In case the COM component is upgraded frequently, what do I need to do to keep my app upgraded too? Do I need to upgrade the interop DLL? Do I need to rebuild and redeploy every time in order to keep up with the COM upgrade?

I don't understand 100% this interoperability issue, and I just need to minimize the work on every COM upgrade. I need to avoid rebuilding and redeploying every time. Is there any optimal way to achieve this?

I've been reading Advanced COM Interoperability ( http://msdn.microsoft.com/en-us/library/bd9cdfyx.aspx ) in MSDN and still don't have clear answer.

Thanks in advance

You should not need to update the interop DLL, as long a the COM interface of the component does not change. Thus, it depends on what kind of changes are being made to the component.

Release notes would be the obvious source of information. Failing that, comparing .tlb files (if they are delivered with the component) might be an option.

Potentially, the component might support multiple interface versions as well, which would make it unnecessary to update your application immediately.

and can't find any tlb file for the COM in question.

It is normally embedded in the COM server DLL. Something you can see with Visual Studio, File + Open + File and select the DLL. You'll see a TYPELIB node, resource 1 is the type library.

You can decompile the type library by running Oleview.exe from the Visual Studio Command Prompt. File + View Typelib and select the DLL. Copy/paste the content of the right pane into a text editor and save it. If there is any change in this IDL then you must rebuild the import library and your program. Not doing so can cause very difficult to diagnose runtime problems that include access violation exceptions and calling the completely wrong method.

This is hard to automate, clearly you'll prefer a better way for the vendor to let you know about breaking changes. The programmer that worked on this server should be well aware of the need for this.

When I am doing COM interop with a component that I might be making lots of builds of, but the COM component isn't changing all that often, then i'll use TLBIMP to make a Interop that I just reference my interop that I can do versioning on (although to version the Interop may require .NET4).

Make all the following a batch file (single line) and use the appropriate tlbimp.

"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\tlbimp" 
"C:\pathtocomdll\comcomponent.dll" 
/out:"Interop.mycomponent.dll" 
/asmversion:"1.1.0.0" /keyfile:"\\server\keyfiles\library.snk"  
/company:"my company"  /productversion:"1.1.0.0" 
/copyright:"2013" 
/product:"company product" /namespace:"company.namespace"

If the COM Component you are using is just upgrading their version but not changing their interface, then you shouldn't need to rebuild your Interop. If you are using .net4 you can also embed the interop in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM