I looked into this with my M54 2.2. It's not viable. It could cost more for a genuine head gasket set alone than the cost of a replacement engine.Do you know what is wrong with the engine? If the numbers stack up, I would prefer to rebuild the original than replace with a (likely) unknown quality unit. Just a thought.
There are plenty of reputable engine suppliers around. And plenty of dodgy ones as well I expect. You just need to do your homework. It's also viable to buy a breaker, particularly a write-off so you can hear it running yourself.