When the scene is actually shot, should the music be playing in the background since the shotgun mic will isolate the dialogue from the background noise? Or should the music be left out entirely and then just added in post?
As others have said, add the music in post. A shotgun mic does not isolate dialogue from background noise. Noise and dialogue are both just sound waves and no mic can tell the difference, they just respond to all sound waves equally, regardless of how we humans decide to differentiate between those sound waves we want and those we don't. Shotgun mics can appear to reduce background noise because they have a very tight pick-up (polar) pattern, meaning they respond to sound waves coming from directly from in front of them much better than they respond to sound waves coming at them from the sides. So, provided of course they are carefully aimed at whoever is speaking, they will pick-up more of the dialogue than the noise. They will never pick-up only the dialogue though because some of the noise will also be coming at the mic in a straight line. In the case of loud music background music, there is no way to stop some of the music sound waves coming straight at the mic and shotguns don't completely reject sound coming from the sides, they're just less sensitive to it.
Take note of Moonshieldmedia's advice! The actors (and the script) have to reflect the fact there should be loud music playing, even though during the filming there isn't any. So, the actors have to yell at each other, move closer to hear better, rely more heavily on gestures/body language and the script should be appropriately littered with (for example) "what" and "say again".
In addition to Moonshieldmedia's workaround (playing the music and then cutting it when "action" is called), another option is to provide dancers and others who need to respond to the music with wireless in ear monitors (IEMs). Although this option is rarely employed by very low budget indie filmmakers because it's relatively expensive to hire the necessary equipment.
-------------------------------
Advanced answer: It is in fact possible to have music playing and not have any of it recorded by the mic! There are some caveats which mean it's not a practical solution in many/most cases but here's how:
Sum the stereo music track to mono, IE. Output the 2 channels of music to 1 audio channel. Output that audio channel to a pair of stereo speakers, IE. Both speakers are playing the exact same signal. Flip the phase of one of the speakers, IE. Consumer speakers usually have 2 audio inputs, 1 red and a 1 white, plug the white cable connector into the speaker's red input and the red cable connector into the speaker's white input (only on one of the speakers). Any point precisely equidistant from both speakers will experience 100% phase cancellation (IE. Silence, no music whatsoever), everywhere else in the room you'll still be able to hear the music, although the closer you get to that equidistant line between the speakers, the more cancellation (less music) you'll experience.
Caveats: Although this is all simple enough in theory, in practice it's fiddly (or impossible) to setup because room acoustics, people, furniture can all subtly change the output of one speaker relative to the other and 100% phase cancellation only occurs when two signals are 100% identical (except for 1 of the signals being 180deg out of phase). This technique is not well suited to the use of lav or boom mics because even an inch or two away from the equidistant position can be enough to significantly reduce the amount of phase cancellation, so a fixed (plant) mic is really required. At one time, this technique was not uncommon in recording studios (where room acoustics are routinely controlled/treated) but it's never been a common technique on film sets. I've only been told of it's use in film, I've never experienced it personally (AFAIK!), although I have experienced it's use in music recording.
OP: My advice would be to ignore this advanced answer! Hardly any amateur filmmakers would even be aware of it's existence (even quite a few pros wouldn't) and even if they do know about it, it still probably wouldn't be a practical solution.
G