How can I set up my Visual Studio project so that I can have one code base which works with both the original VendorApplication COM component (preferably on .NET 4.0 if that's feasible) and the new VendorApplication.Interop.dll (on .NET 4.5)?
One way of doing this is to create two versions of the same "thunk" library, exposing identical API. Each versions should have its own strong name.
The first version (say,
MyInterfaceAssembly.dll
versioned as v4.0.0.1) should target .NET 4.0 and use the old vendor library.The second version (
MyInterfaceAssembly.dll
v4.5.0.1) should target .NET 4.5 and use the new vendor library.You application is build to reference and link with the first version (v4.0.x).
The installer will install either v4.0.x or v4.5.x, depending on the end user system.
The most important part is
app.config
file, where you'd use<bindingRedirect>
:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MyCompany.MyInterfaceAssembly" publicKeyToken="xxxxxxxxxxxxxxxx" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.5.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
On .NET 4.5 your app will run using MyInterfaceAssembly.dll
v4.5.x, provided v4.0.x has not been installed.