I have a managed (asp.net, actually) project that references a COM DLL. Right now, the reference in the .csproj looks like this:
<COMReference Include="thenameinquestion">
<Guid>{someguidhere}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
</COMReference>
This works, but it has the unfortunate consequence that the DLL needs to be registered on the build machine, which means (among other things) it's inconvenient to build multiple versions of the project that use different versions of the DLL on the same build machine.
MSDN shows the ResolveComReference task that looks like it does the right thing, but my google-search-fu hasn't been good enough to come up with an actual example of its usage. Is it possible to do what I want? Am I on the right track?
When you reference a COM DLL, Visual Studio automatically generates an interop assembly for it. I find that taking manual control of this process is a great way to decouple the COM and .NET builds.
tlbimp.exe
. See MSDN for the command line parameters.Once you do this, you no longer have to have the COM DLL registered on the machine when you build the .NET solution, only your interop assembly is required.
The interop assembly can sit in a folder unchanged forever until such time as (a) the COM DLL breaks binary compatibility, or (b) a COM interface change is made that the .NET code actually uses.
If you have different versions of the COM DLL which are all binary compatible, then compile the interop assembly against the earliest version containing the interfaces that the .NET code requires. You will then not have to update the interop assembly for different versions.
In addition, you don't need to include the COM DLL in your installer if you are in a position to assume that the COM DLL will already be installed on the target machine.
As John Fisher pointed out already you are looking for Registration-Free COM Interop. There are plenty of questions already regarding this, look for the 'tag at hand' regfreecom and the closely related tag sxs too.
You'll easily see, however, that this can be a tricky arena, in particular:
Summarizing this I'd like to stress that 'Registration-Free COM Interop' can be very helpful and ease many scenarios a lot. Still it may not make things easier or even be possible at all for your particular scenario and environment (hosted ASP.NET).
Good luck, please let us know whether you succeeded!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With