It's not quite that simple. There was a time when invasion, by definition, meant devastating a country, killing anything that didn't run away fast enough and burning anything you couldn't loot.
Then - in Europe, at least - a concensus developed that soldiers should fight soldiers and try to leave the infrastructure intact and the peasants alive, if only so that a conquered country could pay more tribute. In "Henry V" Shakespeare has a character protest that killing the camp-followers is "contrary to the laws and principles of war." That concensus only really broke down with the Spanish resistance to Napoleon, from which we get the term "guerilla" (Spanish "little war," as distinct from the big one going on between the armies.) The theory generally remains that troops should treat civillians as non-combatants unless proved otherwise: on the grounds that it's a lot easier to subdue a country if you can persuade the locals that your quarrel is not with them personally, and the quickest way to make that impossible is to make it personal by killing their neighbours. To take a recent example, it is often said that the relative success of the British Army in pacifying Helmand Province was due less to their defeat of the Taliban in the field, and more to their humane treatment of Afghan civilians.
The enormous increase in civillian deaths in warfare is not due to troops on the ground, who in the main have become better behaved, but to the predominance of mass slaughter weapons. Whether the same principle should be applied to those is still hotly argued, and not just by armchair generals but by experienced warriors. For example, it is still being fiercely debated whether the RAF's mass bombing of German cities was (quite apart from the moral issues) less effective, in the end, than the pinpoint bombing of strategic targets with minimal collateral damage.