NEW DELHI (Reuters) - India’s ruling and opposition parties condemned U.S. President Donald Trump’s comments this week mocking New Delhi’s role in war-torn Afghanistan, where the South Asian country has invested billion of dollars in economic projects and military training.

FILE PHOTO: U.S. President Donald Trump holds a bilateral meeting with India's Prime Minister Narendra Modi alongside the ASEAN Summit in Manila, Philippines November 13, 2017. REUTERS/Jonathan Ernst/File Photo

The United States and India have drawn closer in recent years as they seek ways to counter-balance China’s spreading influence across Asia.

But Trump’s apparent bid to undermine India’s developmental work in Afghanistan has annoyed not just politicians but also many ordinary Indians.

Trump said on Wednesday he got along very well with Indian Prime Minister Narenda Modi but that Modi was “constantly telling me he built a library in Afghanistan”.

“You know what that is? That’s like five hours of what we spend,” Trump told reporters at the White House. “And we are supposed to say, ‘oh, thank you for the library’. I don’t know who is using it in Afghanistan.”

It was not immediately clear which library Trump was referring to, but both Modi’s Bharatiya Janata Party (BJP) and the main opposition Congress were united in their criticism of the U.S. president.

India has centuries-old ties with Afghanistan and both accuse common neighbor Pakistan of not doing enough to stop Islamist militants operating on their territory. Pakistan denies the charges.

“May be Trump should know that while he is decrying every other help in Afghanistan, India has been building not only libraries, but roads, dams, schools and even parliament building,” Ram Madhav, a BJP general secretary, said on Twitter.

“We are building lives, for which the Afghan people thank us, no matter what others do or don’t.”

Congress said India did not “need sermons from the U.S on Afghanistan”.

The United States has 14,000 troops in Afghanistan, with reports it may be set to withdraw more than 5,000, a sign Trump’s patience is thinning with America’s longest war. Trump has already decided to pull all U.S. troops out of Syria.

Modi’s office did not respond to an email seeking comment. Reuters could not reach the White House outside regular business hours in the United States.

India is the biggest South Asian donor to Afghanistan, spending around $2 billion on reconstruction and rehabilitation, according to the Indian embassy in Kabul. Over the past few years India has helped Afghanistan build roads, erect power transmission lines and construct a parliament building.

Kabul has not yet responded to Trump’s comments.

Afghanistan’s national security advisor, Hamdullah Mohib, is meeting his Indian counterpart Ajit Doval and other officials in New Delhi on Friday.

“Trump mocked India, a key U.S. non-NATO partner that’s done major development work in Afghanistan, for building a library there,” Michael Kugelman, South Asia senior associate at the Washington-based Wilson Center think-tank, said on Twitter. “Sigh.”