Context. A hypothesis for sunspot formation is the buoyant emergence of magnetic flux tubes created by the strong radial shear at the tachocline. In this scenario, the magnetic field has to exceed a threshold value before it becomes buoyant and emerges through the whole convection zone. Aims. We follow the evolution of a random seed magnetic field with the aim of study under what conditions it is possible to excite the dynamo instability and whether the dynamo generated magnetic field becomes buoyantly unstable and emerges to the surface as expected in the flux-tube context. Methods. We perform numerical simulations of compressible turbulent convection that include a vertical shear layer. Like the solar tachocline, the shear is located at the interface between convective and stable layers. Results. We find that shear and convection are able to amplify the initial magnetic field and form large-scale elongated magnetic structures. The magnetic field strength depends on several parameters such as the shear amplitude, the thickness and location of the shear layer, and the magnetic Reynolds number (Rm). Models with deeper and thicker tachoclines allow longer storage and are more favorable for generating a mean magnetic field. Models with higher Rm grow faster but saturate at slightly lower levels. Whenever the toroidal magnetic field reaches amplitudes greater a threshold value which is close to the equipartition value, it becomes buoyant and rises into the convection zone where it expands and forms mushroom shape structures. Some events of emergence, i.e. those with the largest amplitudes of the initial field, are able to reach the very uppermost layers of the domain. These episodes are able to modify the convective pattern forming either broader convection cells or convective eddies elongated in the direction of the field. However, in none of these events the field preserves its initial structure. The back-reaction of the magnetic field on the fluid is also observed in lower values of the turbulent velocity and in perturbations of approximately three per cent on the shear profile. Conclusions. The results indicate that buoyancy is a common phenomena when the magnetic field is amplified through dynamo action in a narrow layer. It is, however, very hard for the field to rise up to the surface without losing its initial coherence.