If dogs are put in their cage when a visitor comes, some dogs will bark all the time in the cage until the visitor leaves. In this case, never let your dog out of the house while he is barking. Dogs have a good memory, so if you let him out even once, he will remember that if he barks, you will get him out.
There are two good ways to stop the barking.
The first way is to lift the house a little when your dog is barking. This will make the floor of the house slanted, leaving him in a very unstable position.
Another way is to silently open the house door and close it when he tries to come out. Then when he starts to bark again, you open the door again, and when he tries to come out again, you close it again. If you repeat this 3 to 4 times, he will not try to come out even if you open the door. When he stops trying to come out, lock the house door, pretending you didn't do anything (it is important).
If he learns that barking can cause discomfort and that you won't let him out of the house when he barks, he stops barking when he is in the house.
Never talk to him when he is barking. It is important to train silently, because calling out will get him excited and encourage barking.