Finite-size effects are investigated in the Gaussian model with isotropic and anisotropic short-range interactions in film geometry with nonperiodic boundary conditions (bc) above, at, and below the bulk critical temperature Tc. We have obtained exact results for the free energy and the Casimir force for antiperiodic, Neumann, Dirichlet, and Neumann-Dirichlet mixed bc in 1<d<4 dimensions. For the Casimir force, finite-size scaling is found to be valid for all bc. For the free energy, finite-size scaling is valid in 1<d<3 and 3<d<4 dimensions for antiperiodic, Neumann, and Dirichlet bc, but logarithmic deviations from finite-size scaling exist in d=3 dimensions for Neumann and Dirichlet bc. This is explained in terms of the borderline dimension d*=3 , where the critical exponent 1-α-ν=(d-3)∕2 of the Gaussian surface energy density vanishes. For Neumann-Dirichlet bc, finite-size scaling is strongly violated above Tc for 1<d<4 because of a cancelation of the leading scaling terms. For antiperiodic, Dirichlet, and Neumann-Dirichlet bc, a finite film critical temperature Tc,film(L)<Tc exists at finite film thickness L . Our results include an exact description of the dimensional crossover between the d -dimensional finite-size critical behavior near bulk Tc and the (d-1) -dimensional critical behavior near Tc,film(L). This dimensional crossover is illustrated for the critical behavior of the specific heat. Particular attention is paid to an appropriate representation of the free energy in the region Tc,film(L)≤T≤Tc. For 2<d<4 , the Gaussian results are renormalized and reformulated as one-loop contributions of the φ4 field theory at fixed dimension d and are then compared with the ε=4-d expansion results at ε=1 as well as with d=3 Monte Carlo data. For d=2 , the Gaussian results for the Casimir force scaling function are compared with those for the Ising model with periodic, antiperiodic, and free bc; unexpected exact relations are found between the Gaussian and Ising scaling functions. For both the d -dimensional Gaussian model and the two-dimensional Ising model it is shown that anisotropic couplings imply nonuniversal scaling functions of the Casimir force that depend explicitly on microscopic couplings. Our Gaussian results provide the basis for the investigation of finite-size effects of the mean spherical model in film geometry with nonperiodic bc above, at, and below the bulk critical temperature.