Norway proclaimed its neutrality at the outset of World War II , but was nonetheless occupied for five years by Nazi Germany ( 1940 - 45 ) .