It is shown that the generating function of $mathscr{N}=2$ topological strings, in the heterotic weak coupling limit, is identified with the partition function of a six-dimensional Melvin background. This background, which corresponds to an exact CFT, realises in string theory the six-dimensional $varOmega$-background of Nekrasov, in the case of opposite deformation parameters $epsilon_1=-epsilon_2$, thus providing the known perturbative part of the Nekrasov partition function in the field theory limit. The analysis is performed on both heterotic and type I strings and for the cases of ordinary $mathscr{N}=2$ and $mathscr{N}=2^*$ theories.