Only the early (1st year or so) E36 had the M42. The later 318i/is/ic/ti/Z3 had the M44, which is a modified version of the M42. I don't know what all of the differences are, but it's a 1.9, rather than 1.8.
I know that the header is different (I have an M44 header that I can't use because it doesn't fit in the E30). Maybe the M42 header would work on the M44. Maybe everything as noted previously would still work, but it you'd be best off consulting with a BMW tech before buying an engine that you may not be able to use.
Neil