The best way is to build a wall about 1/2 - 1 inch away from the foundation. Foundation walls are not flat, but have bows and dips. You will not see these until after the wall is painted. Then its too late.
If you persist, use either concrete screws (such as tapcon) or the powder-driven nailers.