That is difficult to ascertain, because soft body parts like mammary glands are not preserved in the fossil record. Scientists claim that the presence of Harderian glands (or the space for it in the skull) in fossils like Morganucodon (some of the earliest known mammals) show that they most likely had hair. The Harderian gland is still used by some living mammals, such as rodents, to groom their fur with oily secretions. Therefore the presence of such a gland shows that hair most likely had evolved already.
Therefore hair must have evolved really early in mammalian evolution. Since the primary function of hair is to insulate, it follows that endothermy (production of body heat) had also evolved. In fact, whiskers or vibrissae have also been found on some reptiles that are closest to mammals. These reptiles were cynodont therapsian reptiles, and they were about the size of dogs. It is suggested that the whiskers evolved to allow these hunters to feel their way in the dark, as they probably hunted at night to avoid competing with dinosaurs. Later a mutation turned these whiskers into body hair, so the entire body can be insulated.
Even being active at night did not save these close relatives of mammals, as they eventually became extinct, probably because they have no place to hide during the day. The first mammals were small and they spent most of their time underground, safe from dinosaurs. Since these mammals were small, their young must have been tiny, so tiny that they would have a hard time finding food on their own. Therefore it must have been necessary to provide them with food. Therefore it would seem likely that both hair and mammary glands evolved at about the same time in mammals. Hair provides insulation, which are badly needed by a small animal since they lose body heat very quickly due to their proportionally large surface area to body volume ratio. Naked mole rats lack hair but they are not active above ground and they do not have to hunt, unlike the earliest mammals that hunted insects for food.
If I have to guess, hair probably evolved a short time before mammary gland did, They were both needed because they were adaptations to small size in a warm-blooded animal that spent most of its time in underground burrows, where is it cool and where there is no small insect prey. Hair could have evolved in the warm-blooded reptile that was the direct ancestor of the mammals, since they could use the insulation while they hunted at night, the coolest part of the 24 hour day but they would not have needed milk if the young of these dog-sized animals are capable of taking care of themselves as soon as they hatched from their eggs.