Different asmdef per Unity version

How can you specify a different assembly definition file for a different version of Unity?

Unity 2019 moved a whole bunch of assets to separate packages. This means that if a custom package relies on some of that code, it needs to be included in the Assembly Definition References. But those don’t exist in 2018 yet, so 2018 complains if they are included. The rest of the code is identical, so creating a separate package for each version of Unity would be silly.

I thought I could just use two asmdefs and use apply the define constraints !UNITY_2019_1_OR_NEWER and UNITY_2019_OR_NEWER respectively, but that results in Unity saying the folder contains multiple assembly definition files. It is as if the Define Constraints don’t apply to the asmdef itself. Are the Define Constraints only meant for cases where code in a specific folder should be omitted from certain version.

I’m in luck. Unity now seems to be in an odd superposition, where 2019 sees the reference to Unity.Timeline, but 2018 ignores it without complaining. This is using a single assembly definition. It’s not quite clear how I got here, because at first 2018 would not compile anything with that reference in place. This happened after I deleted my attempts at including multiple asmdef files.