Following the reasoning of the Halting Problem, you can indeed make a "virus" that performs the following action:
if (this very virus will not be flagged)
infect everything in sight
else
do nothing
This is practically possible: you just would have to bundle the entire antivirus with your program in order to perform that check.
However, this will not be helpful, because the antivirus can just flag it anyway, despite the fact that in that case it's actually harmless. After all, actual virus-detecting programs are allowed to have false positives, as opposed to that ideal detector from Rice's theorem.
So, in summary: this trick is possible, but it doesn't actually give you any advantage against the antivirus.