The dilemma of modern warfare
The idea of fighting a war while keeping clean hands is a tempting one. The wars of the 20th century, particularly the Second World War, involved such massive casualties that neither we, nor other Western nations, want to pay such a price again. The deaths were hardly limited to the military, either:
World War II was the deadliest military conflict in history. An estimated total of 60–75 million deaths were caused by the conflict … This represents about 3% of the estimated global population of 2.3 billion in 1940. Deaths directly caused by the war (including military and civilian fatalities) are estimated at 50–56 million, with an additional estimated 19–28 million deaths from war-related disease and famine. Civilian deaths totaled 50–55 million. Military deaths from all causes totaled 21–25 million, including deaths in captivity of about 5 million prisoners of war.
Those are estimates, of course. But we won’t quibble here; the point is that a lot of people died and a great many were civilians. Many civilians died from bombing that deliberately targeted civilians, or from killing fields and camps that performed mass murder of the premeditated kind. The US was spared those civilian deaths, but certainly saw the suffering that resulted from them abroad.
Atomic weapons targeting civilians ended the war with Japan. It is a paradox that the enormous number of civilian casualties in Hiroshima and Nagasaki probably spared the deaths of many more by hastening the Japanese surrender (see my posts here).
By the time of the Vietnam War, our opponents had learned a thing or two. This was a guerilla war and a war of propaganda. The enemy read the US very well, and realized we didn’t have the stomach to go on and on and on. Also, it was as a result of the Vietnam War that the US draft ended and our military became all- volunteer, which removed most citizens from much knowledge of the calculations involved in fighting a war.
Later, instruments of war became more accurate. Our bombs are now relatively “smart,” certainly compared to in WWII or Vietnam. That doesn’t mean there is no collateral damage in which civilians die. But we don’t target civilians, and we have very little tolerance for the death of civilians even when it occurs by accident. These are not bad things; I think it’s a good thing to have compassion for civilians in war and even to try not to have many military casualties in war, if possible. But the unintended consequence is that it becomes more and more difficult, despite our technology, to definitively end a war against a foe who’s determined to resist and to use against us our reluctance to inflict massive harm on civilians or to put our own boots on the ground.
Terrorists and terrorist regimes have no such reluctance. Au contraire; they target civilians. Not only do they target civilians in terrorist attacks, but they also willingly put their own civilians in harms’ way, the better to accuse us of barbarity when we inevitably kill some of them.
[NOTE: See also this previous post of mine on clean hands in war, as well as this one.]

The first question: Can it be done?
Next question the answer leads to question 1)
When does it have to be done?
Civilians of the enemy are part of the enemy. That was accepted in the European war against the Nazi forces. Dresden is often cited by the Left as an example of attacking civilians. But the Left will kill you quicker than fast unless you adhere to their dogmas. The major mass murderers of the twentieth century have all been Leftists- Stalin, Mao, Pol Pot among them. AFAIC, Leftists are evil.
The dilemma of modern warfare is the dilemma of all warfare: the only sin is not winning. That sounds incredibly amoral. War is not moral, it is necessary.
Hopefully it will not be necessary forever.