I have read the answers to Do you put unit tests in same project or another project? and the consensus back then (almost 10 years ago) is to put unit tests in a separate project from the code they are testing. The main reason given is to avoid non-production code from being deployed, which is fairly sound.
Things have moved on a lot since then, and at least for JavaScript based projects, having our tests next to the code is the norm, and indeed most consider it highly desirable. But I won't go into the advantages here as it's not what this question is about.
Assuming we want the same thing for C#, but still avoid deploying test code to prod, is there some post-compilation magic we can weave at the IL level to strip out the tests from the binary as part of the build process? For example could we search and destroy all classes from the binary with the [TestFixture]
attribute?
Could we harness some feature of Roslyn to achieve the same?
Alternatively, is there some other approach we can take?