I can only comment from the point of view of using ODIS for this but here is some info:
If you have a genuine OEM key that is original to the car then that stops a lot of issues with immo matching.
In order to match new immo parts then at least 1 of the existing immo parts still fitted needs to have the correct VIN for it to work without problems.
Also, the part numbers needs to be EXACTLY correct for the VIN, so either same as original from factory or a valid superseded part. This can be verified with ETKA.
The Immo master is in the clocks so you can't generally hot swap the clocks, especially if you're swapping ECUs around too. This isn't always the case but for the purpose of ease with your issue, lets say you can't hot swap them.
So firstly, I'd get a good diagnostic scan (ODIS is best but VCDS will do) to determine WHERE the immo fault is coming from, then you'll know where to fix.
If it turns out to be the ECU then I'd check that the replacement ECU you have is the right part number and SW version. Then, providing it's not a stolen part (not you having stolen it but it bought from someone that has on ebay or alike) and the numbers are good then it should match without fuss. You won't need to re-match the key as the key is matched to the clocks, not the ECU, so you can skip that part during the immo match process.
If the
problem is in the clocks then the original ECU would need to be present for the clocks to match to the car without fuss and the key will need to be matched to the clocks.
I've not mentioned the gearbox as you've not said if it's manual or DSG but if it's DSG then that forms part of the immo system too.