Is it possible to reference a COM DLL in a managed project by path rather than by GUID?
.net, com, msbuild
Solution
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.
- Create your own interop assembly for the COM DLL using `tlbimp.exe`. See MSDN for the command line parameters.
- Reference your interop assembly in the .NET project instead of the COM DLL.
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.
Problem
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?