This depends largely on a few things you didn't state very clearly, so let's dive in to it a bit. I'm assuming that as of version 1, all the files are unique between the installers, or are properly shared and are not relevant to the code you're talking about migrating (so can be ignored for this question).
Case 1: Code X migrates between DLLs, e.g. A installs a.dll; B installs b.dll, and code is moving from b.dll to a.dll
In this case, assuming there are no call chains across the two products, you've got nothing special do do. Simply have A.2 replace a.dll with the next version, and B.2 replace b.dll with the next version. There are no concerns about order of installation, or multiple ownership of DLLs.
This approach should work with any kind of upgrade, so long as the DLL versioning allows the DLLs to be properly replaced.
If there is a published interface (such as a COM class), then there may be a required order to the update to ensure that b.dll relinquishes the registration reference before a.dll takes it, however these changes violate component rules.
Case 2: Code X's dll migrates between installers, e.g. B installs c.dll, and that dll will now instead be installed by A
In this case, your success will depend on the quality of your initial authoring. If the c.dll is installed by its own component and is marked shared, you can add that component to A (matching its settings), and an upgrade will work smoothly in either order. If you install A.2 first, it will add to the reference count, so intalling B.2 will unreference but not remove it. If you install B.2 first, it will temporarily remove c.dll, but installing A.2 will restore it. Uninstallation will work similarly, tracking reference counts and removing as necessary.
But this assumes a major upgrade. If you're using a minor upgrade (whether delivered as a .msp or .msi), you are in a much more difficult scenario. For B's upgrade path to be clean, it has to keep the c.dll component around and choose an alternate approach to remove c.dll. However all of the approaches I know conflict with A installing an exact copy of the same component in the same place. For this case, installing B.2 first should work, but installing it second might remove c.dll.
If minor upgrades could work correctly, you might have to also consider the case of a patch uninstall, but since they cannot, I won't cover that here.