  We study a solid protoplanetary core of 1-10 earth masses migrating through a
disk. We suppose the core luminosity is generated as a result of planetesimal
accretion and calculate the structure of the gaseous envelope assuming
equilibrium. This is a good approximation when the core mass is less than the
critical value, M_{crit}, above which rapid gas accretion begins. We model the
structure of the protoplanetary nebula as an accretion disk with constant
\alpha. We present analytic fits for the steady state relation between disk
surface density and mass accretion rate as a function of radius r. We calculate
M_{crit} as a function of r, gas accretion rate through the disk, and
planetesimal accretion rate onto the core \dot{M}. For a fixed \dot{M},
M_{crit} increases inwards, and it decreases with \dot{M}. We find that \dot{M}
onto cores migrating inwards in a time 10^3-10^5 yr at 1 AU is sufficient to
prevent the attainment of M_{crit} during the migration process. Only at small
radii where planetesimals no longer exist can M_{crit} be attained. At small
radii, the runaway gas accretion phase may become longer than the disk lifetime
if the core mass is too small. However, massive cores can be built-up through
the merger of additional incoming cores on a timescale shorter than for in situ
formation. Therefore, feeding zone depletion in the neighborhood of a fixed
orbit may be avoided. Accordingly, we suggest that giant planets may begin to
form early in the life of the protostellar disk at small radii, on a timescale
that may be significantly shorter than for in situ formation. (abridged)
