I doubt that this can be achieved but you can get most things most of the time if the code you build has a manifest and version control block. This means that any source you want to build from elsewhere will have to have this added if its missing. The basic things to comprehend are use a normal 32 or 64 bit COFF header that has no extra junk in it, the manifest and version control block, don't try and run a tiny test piece as it is probably too short for an AV scanner to comprehend and avoid any messy complex branching at the start of the code just after then entry point.
The better end of AV scanners don't have the problem and will actually look at the code rather than just a check list of parts but if you get these right, you will survive most crappy AV scanners.