This seems to be indeed a myth.
The Barry-Museum, the museum in Bern where the most famous of the St. Bernhard dogs is exhibited, states in its English brochure:
One of the best-known Barry legends is that of the small barrel of
‘eau-de-vie’ that the dogs were believed to have carried around their
necks so that exhausted travellers (sic!) could revive themselves
with a stiff drink. All over the world, the famous barrel is firmly
embedded in the public imagination, and virtually every Saint Bernard
featured in advertising or tourist brochures is seen with this
accessory around its neck. However, the barrels belong to the realm of
fantasy. Some dogs were probably accustomed to carrying provisions in
small ‘packsaddles’ from time to time, but the first appearance of the
barrels in pictures was not until the end of the 19th century. The
barrel became a recognized symbol, the use of which was a success
story in the early days of marketing. In 1956 a chaplain at the
hospice put the story straight regarding the small barrels of rum: ‘At
no point in time did the dogs carry such barrels’.
I guess this is a bit more authoritative than Wikipedia or the other sources given so far.
(German version here)
The German Wikipedia claims (permalink) explains its likely origin:
Viele der mythischen Geschichten um den Hund sind denn auch frei
erfunden, wurden aber so oft weitererzählt und umgeschrieben, dass es
schwierig ist, Wahrheit von Legende zu trennen. Dazu zählt auch das
berühmte Schnapsfässchen, das die Hunde auf jeder Abbildung um den
Hals tragen, angeblich um den Lawinenopfern einen Schluck daraus zur
Aufwärmung zu geben. Die Legende entstammt vermutlich einem Brief, den
einer der Soldaten Napoleons beim Zug über den St. Bernhard schrieb.
Die völlig überforderten Chorherren hatten die Hunde als
Transporttiere eingesetzt, um den erschöpften Soldaten Verpflegung zu
bringen. In diesem Brief stand: «Wir staunen darüber, dass es in
diesem Kloster sehr große Hunde gibt, die Reisende aufspüren, die im
Schnee verloren gingen. Sie richten sie auf, bieten ihnen Branntwein
dar, den sie um den Hals gebunden mitführen und führen sie ins Haus.»
Die Geschichte wurde mündlich weitererzählt und in verschiedenen
Filmen als Motiv aufgenommen, ihr Wahrheitsgehalt ist jedoch höchst
umstritten. Einige der erhalten gebliebenen Fässchen zeigen, dass es
sich wohl nur um ein Schmuckstück handelte, denn diese Fässer haben
keine Öffnung. Dazu wäre das Fass für die Hunde bei der Suche nach
Verschütteten im tiefen Schnee sehr hinderlich – ganz abgesehen von
der Tatsache, dass der Konsum von Alkohol bei Unterkühlung
kontraproduktiv ist.
In English:
Many of the mythical stories surrounding the dog (race) are simply
invented but were passed on and changed so many times that it is
hard to separate truth from legend. Within this scope lies the famous
schnapps casks some of the dogs carry around their necks on pictures,
allegedly to offer avalanche victims (literal transl.) a gulp from it to warm up.
The legend likely originates from a letter one of Napoleons soldiers wrote
during their move across St. Bernhard.
Some clerics used the dogs for transport to provide the exhausted soldiers with
supplies.
This letter said: "We are amazed that this monastery has huge dogs that are able
to find travelers who got lost in the snow. They spirit them (i.e. the lost travelers)
up and offer them brandy which they carry bound around their necks and lead them into
a house."
The story was passed on orally and was picked up as motif by several movies,
its truth however is highly controversial.
Some remaining barrels show that these were likely just trinkets because these barrels
have no openings.
Additionally the barrel would be very cumbersome in deep snow - not to mention the fact
that the consumption of alcohol in a state of hypothermia is counterproductive.
I tried to stay as true as possible to the original content in my translation. The italic parts in parentheses are my comments and the link to St. Bernhard is for informational purposes.
The mentioned "type" of clerics seems to be specific to German-speaking regions, at least I couldn't find anything coming close enough to it, so I was stuck with the generic term here.
Another source, Swiss-German (website of a newspaper) claims a different, but also French origin - translation of the contents to English:
Who imputed the St. Bernhard its cask?
[...] In actuality the dogs of the (St. Bernard) Hospice never
carried such barrels. Creator of the legend is likely Anne François
Joachim Fréville (French Wikipedia), a French pedagogue,
historian and writer. Towards the end of the 18th century he published
other than "Les Enfants célèbres" his "Histoire des chiens célèbres"
with a chapter about Swiss avalanche dogs with their survival water
(literally "Überlebenswasser").