Normally the Mass itself is the only context in which the Bread and Wine are consecrated at which time transubstantiation occurs.
In extraordinary cases, ie there is no time for a full Mass to be offered, and someone will die without the sacraments, a priest may offer the bread and wine to God with the inetent of consecrating them, and consecrate the elements using the words, “This is my body” and, “This is my blood” in order that the person who may die without the sacraments can have the viaticum. Since most Churches and chapels have the Blessed Sacrament reserved for the sick, it is a very rare event, and if at all possible the priest should include all the rites of the Mass.
For a Mass to be a valid Mass, the priest must do the above, and consume the elements. To be licit, or legal it must follow the rubrics, or instructions in the Missal, unless there is some very good reason to not do so. So if the offeretory, consecration and emolation or consumption of the sacrifice takes place, even though all the ceremonies are not used, (for good reason) it is a Mass.