They could have skipped that. Spent all the money directly on the good outcome that didn't happen at all. There is - I speculate, keeping to my rather thick sarcasm - a link.
Investment -> Prosperity.
Army -> Corpses and destruction.
I recommend not sending in an army when the goal is prosperity. Invasions are sometimes clever, but they don't make the situation better for the locals. And in the case of Afghanistan it was unnecessary.
The problem with dictatorships of all kinds is that there are very few foreign investors willing to invest money into them. Why should anyone invest into a country that can seize your assets for no reason at all, where female staff has virtually zero rights, where there is no educated populace that can be used for work or where there isn't any industry generating income to repay investments? Most dictatorships have a barely surviving 99% and a small elite that holds the power and skims assets for their personal wealth.
It's rare that revolutions are successful even in taking down the current regime, and the few that do succeed often fail very shortly afterwards because the security services like police and military are loyal to the old leader, too corrupt to be useful, the absence of a ruling power leads to a vacuum that draws in foreign warlords or other regimes or because the prior dictatorship has looted the country's assets and stashed the profit somewhere the post-revolution government can't access it. Additionally, some revolutions also fail and become autocracies of their own due to foreign influence (e.g. the US sanctions against Cuba).
Revolutions without an external force providing basic stability are doomed to failure and suffering.
The reason why Germany is where it is now is that the US sunk billions upon billions into the Marshall Plan and had shown the commitment that they would stay in the country and provide it perspective and security if it would become and stay a healthy democracy that respects the rule of law.
The US had done everything precisely opposite in Afghanistan: they marched in and got rid of the Taliban government, but they failed to enforce a rule of law in the country and instead let local warlords and other undesirables deal with that. Corruption was rife everywhere, and there was no economic perspective for the people of Afghanistan to be a somewhat self-sufficient country. Hell even after 20 years, 75% (!) of the budget was foreign aid [1].
As a result of that lack of perspective, why should the Afghani people have any respect for its "government" that barely had any shred of legitimacy? At least Iraq has natural resources.
What the West should have done in Afghanistan was to do the same thing it had done in Germany half a century before: invest in nation building, in providing the citizens a path that is not violence, poverty and crime.
[1] https://www.pbs.org/wgbh/frontline/article/taliban-takeover-...