In a recent contribution [Phys. Rev. Lett. 91, 046101 (2003)] we used polarization-dependent, $\mathrm{Ni}$ $K$ edge, x-ray absorption spectroscopy (XAS) to probe the structure of ultrathin $\mathrm{NiO}$ epilayers deposited on $\mathrm{Ag}(001)$. In that experiment samples were measured ex-situ and a $5\phantom{\rule{0.3em}{0ex}}\mathrm{ML}$-thick $\mathrm{MgO}$ cap was used to avoid the hydroxylation of the $\mathrm{NiO}$ film. In the present paper we report complementary $\mathrm{O}$ $K$ edge XAS data on the same system; $\mathrm{NiO}$ epilayers, in the $3--50\phantom{\rule{0.3em}{0ex}}\mathrm{ML}$ thickness range, were grown in situ in the end station of the ALOISA beamline of the ELETTRA facility. A quantitative analysis of the data in the extended energy range has been performed using multiple scattering simulations. We found that, even in the ultrathin limit, the local structure of the film is rock-salt and we obtained a quantitative evaluation of the average in-plane and out-of-plane film strain as a function of the film thickness $T$. An in-plane compressive strain, due to lattice mismatch with the $\mathrm{Ag}$ substrate, is clearly present for the $3\phantom{\rule{0.3em}{0ex}}\mathrm{ML}$ film, being the in- and out-of-plane nearest neighbor distances equal to ${r}_{\ensuremath{\Vert}}=2.048\ifmmode\pm\else\textpm\fi{}0.016\phantom{\rule{0.3em}{0ex}}\mathrm{\AA{}}$ and ${r}_{\ensuremath{\perp}}=2.116\ifmmode\pm\else\textpm\fi{}0.018\phantom{\rule{0.3em}{0ex}}\mathrm{\AA{}}$. These values are in agreement with the expected behavior for a tetragonal distortion of the unit cell. The growth-induced strain is gradually released with increasing $T$: it is still appreciable for $10\phantom{\rule{0.3em}{0ex}}\mathrm{ML}$ but is completely relaxed at $50\phantom{\rule{0.3em}{0ex}}\mathrm{ML}$. Any significant intermixing with the $\mathrm{Ag}$ substrate has been ruled out. Combining $\mathrm{O}$ and $\mathrm{Ni}$ $K$ edge results we can conclude that $\mathrm{NiO}$ films grow on $\mathrm{Ag}(001)$ in the O-on-$\mathrm{Ag}$ configuration, with an interface distance $d=2.28\ifmmode\pm\else\textpm\fi{}0.08\phantom{\rule{0.3em}{0ex}}\mathrm{\AA{}}$. This expansion of the interplanar distance is in agreement with recent ab initio simulations. A comparison with the similar $\mathrm{MgO}∕\mathrm{Ag}(001)$ system is also performed.