Preheat the oven to 375°F and spray a 9x13-inch baking pan with nonstick spray.
Cook the macaroni according to the package directions.
While the macaroni is cooking, prepare the cheese sauce: In a saucepan over medium heat, sauté the onion in butter until soft and transparent. Add the flour and pepper and cook for 1 minute, stirring constantly. Slowly add the milk while continuing to stir. Cook over medium heat until the mixture thickens. Add the cheese gradually and stir constantly until all of the cheese is melted.
Drain the macaroni and return it to the pot. Pour the cheese sauce over the macaroni and mix well.
Pour the macaroni into the prepared baking pan and bake for 30 minutes.